2

是否有任何适用于 Closure Compiler 的类类继承的 JavaScript 实现ADVANCED_OPTIMIZATIONS

看起来John Resig 的实现没有。

4

2 回答 2

0

这是设置继承的最简单且非常常见的方法之一:

function Parent() {}

function Child() {}

Child.prototype = Object.create(Parent.prototype);
Child.prototype.constructor = Child;

它适用于闭包编译器。我不确定是否Object.create正确识别,但看看goog.inherits闭包库的实现,它基本上是一样的。

于 2013-03-22T09:18:01.670 回答
0

编译器目前仅识别“goog.inherits”并直接分配给原型:

Child.prototype = new Parent();

Object.create 隐喻是一个明显的补充,但还没有完成。要让其他任何东西被识别,要么需要定义新的编码约定类(这是在类型检查期间识别 goog.inherits 的方式),要么需要更改编译器(Object.create 可能需要)。

如果需要对 Object.create 的支持,您需要在此处提交问题:

https://code.google.com/p/closure-compiler/issues/list

于 2013-03-25T16:45:06.763 回答