Merge pull request #1686 from danyaPostfactum/object-create
Use Object.create for inheritance
This commit is contained in:
commit
a7798c4497
1 changed files with 18 additions and 5 deletions
|
|
@ -32,12 +32,25 @@ define(function(require, exports, module) {
|
|||
"use strict";
|
||||
|
||||
exports.inherits = (function() {
|
||||
var tempCtor = function() {};
|
||||
var createObject = Object.create || function(prototype, properties) {
|
||||
var Type = function () {};
|
||||
Type.prototype = prototype;
|
||||
object = new Type();
|
||||
object.__proto__ = prototype;
|
||||
if (typeof properties !== 'undefined' && Object.defineProperties) {
|
||||
Object.defineProperties(object, properties);
|
||||
}
|
||||
};
|
||||
return function(ctor, superCtor) {
|
||||
tempCtor.prototype = superCtor.prototype;
|
||||
ctor.super_ = superCtor.prototype;
|
||||
ctor.prototype = new tempCtor();
|
||||
ctor.prototype.constructor = ctor;
|
||||
ctor.super_ = superCtor;
|
||||
ctor.prototype = createObject(superCtor.prototype, {
|
||||
constructor: {
|
||||
value: ctor,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
};
|
||||
}());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue