Tag: object create

JavaScriptinheritance:Object.create vs new

在JavaScript中这两个例子有什么区别: 先决条件: function SomeBaseClass(){ } SomeBaseClass.prototype = { doThis : function(){ }, doThat : function(){ } } inheritance示例A使用Object.create: function MyClass(){ } MyClass.prototype = Object.create(SomeBaseClass.prototype); inheritance示例B使用新的关键字 function MyClass(){ } MyClass.prototype = new SomeBaseClass(); 这两个例子似乎都是一样的。 你什么时候select一个呢? 还有一个问题:考虑下面的链接(第15行)中的代码,其中对函数自己的构造函数的引用存储在原型中。 为什么这是有用的? https://github.com/mrdoob/three.js/blob/master/src/loaders/ImageLoader.js 摘录(如果你不想打开链接): THREE.ImageLoader.prototype = { constructor: THREE.ImageLoader }