inherits-ex
Advanced tools
Comparing version 1.5.4 to 1.6.0
@@ -7,2 +7,4 @@ var isArray = Array.isArray; | ||
var getSuperCtor = require('./getSuperCtor'); | ||
var getRootCtor = require('./getRootCtor'); | ||
var getClosestCommonAncestorCtor= require('./getClosestCommonAncestorCtor'); | ||
@@ -28,9 +30,5 @@ /** | ||
inheritsDirectly(ctor, superCtor, staticInherit); | ||
// patch the missing prototype chain if exists ctor.super. | ||
while (v != null && v !== Object && superCtor !== v) { | ||
ctor = superCtor; | ||
superCtor = v; | ||
inheritsDirectly(ctor, superCtor, staticInherit); | ||
v = getSuperCtor(ctor); | ||
} | ||
var rootCtor = getClosestCommonAncestorCtor(v, superCtor) | ||
superCtor = getRootCtor(superCtor, rootCtor) | ||
if (v && v !== Object) inheritsDirectly(superCtor, v) | ||
result = true; | ||
@@ -37,0 +35,0 @@ } else if (isInherited) { |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/snowyu/inherits-ex.js", | ||
"version": "1.5.4", | ||
"version": "1.6.0", | ||
"author": { | ||
@@ -8,0 +8,0 @@ "name": "Riceball LEE", |
@@ -7,2 +7,4 @@ var isArray = Array.isArray; | ||
var getSuperCtor = require('./getSuperCtor'); | ||
var getRootCtor = require('./getRootCtor'); | ||
var getClosestCommonAncestorCtor= require('./getClosestCommonAncestorCtor'); | ||
@@ -28,9 +30,5 @@ /** | ||
inheritsDirectly(ctor, superCtor, staticInherit); | ||
// patch the missing prototype chain if exists ctor.super. | ||
while (v != null && v !== Object && superCtor !== v) { | ||
ctor = superCtor; | ||
superCtor = v; | ||
inheritsDirectly(ctor, superCtor, staticInherit); | ||
v = getSuperCtor(ctor); | ||
} | ||
var rootCtor = getClosestCommonAncestorCtor(v, superCtor) | ||
superCtor = getRootCtor(superCtor, rootCtor) | ||
if (v && v !== Object) inheritsDirectly(superCtor, v) | ||
result = true; | ||
@@ -37,0 +35,0 @@ } else if (isInherited) { |
@@ -169,3 +169,7 @@ var chai = require('chai') | ||
class MyClass{} | ||
assert.equal(inherits(C, Root), true) | ||
class B{} | ||
// C -> Root | ||
assert.equal(inherits(C, Root), true); | ||
// B -> Root | ||
assert.equal(inherits(B, Root), true); | ||
@@ -183,2 +187,22 @@ //# MyClass -> B -> Root | ||
}) | ||
it("should multi-inheritances and void circular inherit2", () => { | ||
class Ctor {} | ||
class CtorParent {} | ||
class CtorRoot {} | ||
inherits(Ctor, [CtorParent, CtorRoot]) | ||
class SuperCtor {} | ||
class SuperParent {} | ||
inherits(SuperCtor, SuperParent) | ||
assert.equal(inherits(Ctor, SuperCtor), true); | ||
assert.deepEqual(getProtoChain(Ctor), ['CtorRoot', 'CtorParent', 'SuperParent', 'SuperCtor', 'Ctor']); | ||
}); | ||
it("should multi-inheritances and void circular inherit3", () => { | ||
class CtorRoot {} | ||
class CtorParent extends CtorRoot{} | ||
class Ctor extends CtorParent{} | ||
class SuperParent {} | ||
class SuperCtor extends SuperParent{} | ||
assert.equal(inherits(Ctor, SuperCtor), true); | ||
assert.deepEqual(getProtoChain(Ctor), ['CtorRoot', 'CtorParent', 'SuperParent', 'SuperCtor', 'Ctor']); | ||
}); | ||
it("test isInheritedFrom with class name", function(){ | ||
@@ -185,0 +209,0 @@ isInheritedFrom = isInheritedFrom |
@@ -168,3 +168,7 @@ var chai = require('chai') | ||
function MyClass() {}; | ||
function B() {}; | ||
// C -> Root | ||
assert.equal(inherits(C, Root), true); | ||
// B -> Root | ||
assert.equal(inherits(B, Root), true); | ||
// MyClass -> B -> Root | ||
@@ -180,2 +184,15 @@ assert.equal(inherits(MyClass, B), true); | ||
}); | ||
it("should multi-inheritances and void circular inherit2", () => { | ||
function Ctor() {} | ||
function CtorParent() {} | ||
function CtorRoot() {} | ||
function SuperCtor() {} | ||
function SuperParent() {} | ||
// Ctor -> CtorParent -> CtorRoot | ||
inherits(Ctor, [CtorParent, CtorRoot]) | ||
// SuperCtor -> SuperParent | ||
inherits(SuperCtor, SuperParent) | ||
assert.equal(inherits(Ctor, SuperCtor), true); | ||
assert.deepEqual(getProtoChain(Ctor), ['CtorRoot', 'CtorParent', 'SuperParent', 'SuperCtor', 'Ctor']); | ||
}); | ||
it("test isInheritedFrom with class name", function() { | ||
@@ -182,0 +199,0 @@ assert.equal(isInheritedFrom(A, 'Root'), A); |
226574
133
5506