inherits-ex
Advanced tools
Comparing version 1.3.5 to 1.3.6
@@ -21,3 +21,3 @@ var isArray = Array.isArray; | ||
* @param {function} superCtor Constructor function to inherit prototype from. | ||
* @param {boolean} staticInherit whether static inheritance,defaults to true. | ||
* @param {boolean} staticInherit whether allow static members inheritance,defaults to true. | ||
*/ | ||
@@ -24,0 +24,0 @@ function inherits(ctor, superCtor, staticInherit) { |
@@ -13,3 +13,3 @@ var newPrototype = require('./newPrototype'); | ||
defineProperty(ctor.prototype, 'constructor', vPrototype.constructor) | ||
defineProperty(ctor.prototype, 'Class', vPrototype.Class) | ||
defineProperty(ctor.prototype, 'Class', ctor) | ||
} | ||
@@ -20,4 +20,4 @@ // console.log('TCL:: ~ file: inheritsDirectly.js ~ line 11 ~ ctor.prototype', ctor.prototype, ctor.prototype.constructor, ctor.prototype.Class); | ||
// NOTE: ES6 use this to keep superCtor. | ||
setPrototypeOf(ctor, superCtor); // additional static inheritance | ||
setPrototypeOf(ctor, superCtor); // additional static member inheritance | ||
} | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/snowyu/inherits-ex.js", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"author": { | ||
@@ -8,0 +8,0 @@ "name": "Riceball LEE", |
@@ -68,2 +68,3 @@ # Inherits-Ex [![npm](https://img.shields.io/npm/v/inherits-ex.svg)](https://npmjs.org/package/inherits-ex) | ||
const inherits = require('inherits-ex/lib/inherits') | ||
const getPrototypeOf = require('inherits-ex/lib/getPrototypeOf') | ||
@@ -86,6 +87,12 @@ // Or use function class instead of ES6 class: | ||
// Or use function Root instead of ES6 class | ||
// MUST BE EXISTS constructor to call parent constructor if it's ES6 class | ||
// */ | ||
constructor() { | ||
this.initialize.apply(this, arguments) | ||
if (!this.Class) this.Class = getPrototypeOf(this).constructor | ||
const Parent = getParentClass(this.Class) | ||
// create the instance by calling the parent constructor | ||
return Reflect.construct(Parent, arguments, this.Class) | ||
// or call initialize method directly | ||
// this.initialize.apply(this, arguments) | ||
} | ||
// */ | ||
@@ -92,0 +99,0 @@ initialize() { |
@@ -21,3 +21,3 @@ var isArray = Array.isArray; | ||
* @param {function} superCtor Constructor function to inherit prototype from. | ||
* @param {boolean} staticInherit whether static inheritance,defaults to true. | ||
* @param {boolean} staticInherit whether allow static members inheritance,defaults to true. | ||
*/ | ||
@@ -24,0 +24,0 @@ function inherits(ctor, superCtor, staticInherit) { |
@@ -13,3 +13,3 @@ var newPrototype = require('./newPrototype'); | ||
defineProperty(ctor.prototype, 'constructor', vPrototype.constructor) | ||
defineProperty(ctor.prototype, 'Class', vPrototype.Class) | ||
defineProperty(ctor.prototype, 'Class', ctor) | ||
} | ||
@@ -20,4 +20,4 @@ // console.log('TCL:: ~ file: inheritsDirectly.js ~ line 11 ~ ctor.prototype', ctor.prototype, ctor.prototype.constructor, ctor.prototype.Class); | ||
// NOTE: ES6 use this to keep superCtor. | ||
setPrototypeOf(ctor, superCtor); // additional static inheritance | ||
setPrototypeOf(ctor, superCtor); // additional static member inheritance | ||
} | ||
}; |
@@ -192,8 +192,8 @@ var chai = require('chai') | ||
it("test inheritsObject", function(){ | ||
cMethod = ()=> "cMethod" | ||
C = function(){return "C"} | ||
var cMethod = ()=> "cMethod" | ||
var C = function(){return "C"} | ||
C.name = "C" | ||
C.prototype.cMethod = cMethod | ||
b = new B() | ||
var b = new B() | ||
assert.equal(inheritsObject(b, C), true) | ||
@@ -205,3 +205,4 @@ // bProto = b.__proto__ | ||
assert.equal(C.super_, B) | ||
b1 = new B() | ||
var b1 = new B() | ||
b1.should.have.property('Class', B) | ||
assert.equal(inheritsObject(b1, C), true) | ||
@@ -215,14 +216,14 @@ // bProto = b1.__proto__ | ||
it("test inheritsDirectly and isInheritedFrom", function(){ | ||
cMethod = ()=> "cMethod" | ||
R = function(){return "R"} | ||
var cMethod = ()=> "cMethod" | ||
var R = function(){return "R"} | ||
R.name = "R" | ||
C = function(){return "C"} | ||
var C = function(){return "C"} | ||
C.name = "C" | ||
C.prototype.cMethod = cMethod | ||
C1 = ()=> "C1" | ||
var C1 = ()=> "C1" | ||
C1.name = "C1" | ||
C11 = ()=> "C11" | ||
var C11 = ()=> "C11" | ||
C11.name = "C11" | ||
C2 = ()=> "C2" | ||
var C2 = ()=> "C2" | ||
@@ -229,0 +230,0 @@ assert.ok(inherits(C, R), "C inherits from R") |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130503
85
2363
385