inherits-ex
Advanced tools
Comparing version 1.3.4 to 1.3.5
@@ -5,2 +5,3 @@ var isArray = Array.isArray; | ||
var getPrototypeOf = require('./getPrototypeOf'); | ||
var defineProperty = require('./defineProperty'); | ||
@@ -31,3 +32,4 @@ var objectSuperCtor = getPrototypeOf(Object); | ||
var result = false; | ||
if (!isInheritedFrom(ctor, superCtor) && !isInheritedFrom(superCtor, ctor)) { | ||
var isInherited = isInheritedFrom(ctor, superCtor) | ||
if (!isInherited && !isInheritedFrom(superCtor, ctor)) { | ||
inheritsDirectly(ctor, superCtor, staticInherit); | ||
@@ -42,2 +44,11 @@ // patch the missing prototype chain if exists ctor.super. | ||
result = true; | ||
} else if (isInherited) { | ||
// additional properties | ||
if (!ctor.hasOwnProperty('super_')) { | ||
defineProperty(ctor, 'super_', superCtor); | ||
defineProperty(ctor.prototype, 'Class', ctor) | ||
} | ||
if (!ctor.hasOwnProperty('__super__')) { | ||
defineProperty(ctor, '__super__', superCtor.prototype); | ||
} | ||
} | ||
@@ -44,0 +55,0 @@ return result; |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/snowyu/inherits-ex.js", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"author": { | ||
@@ -8,0 +8,0 @@ "name": "Riceball LEE", |
@@ -5,2 +5,3 @@ var isArray = Array.isArray; | ||
var getPrototypeOf = require('./getPrototypeOf'); | ||
var defineProperty = require('./defineProperty'); | ||
@@ -31,3 +32,4 @@ var objectSuperCtor = getPrototypeOf(Object); | ||
var result = false; | ||
if (!isInheritedFrom(ctor, superCtor) && !isInheritedFrom(superCtor, ctor)) { | ||
var isInherited = isInheritedFrom(ctor, superCtor) | ||
if (!isInherited && !isInheritedFrom(superCtor, ctor)) { | ||
inheritsDirectly(ctor, superCtor, staticInherit); | ||
@@ -42,2 +44,11 @@ // patch the missing prototype chain if exists ctor.super. | ||
result = true; | ||
} else if (isInherited) { | ||
// additional properties | ||
if (!ctor.hasOwnProperty('super_')) { | ||
defineProperty(ctor, 'super_', superCtor); | ||
defineProperty(ctor.prototype, 'Class', ctor) | ||
} | ||
if (!ctor.hasOwnProperty('__super__')) { | ||
defineProperty(ctor, '__super__', superCtor.prototype); | ||
} | ||
} | ||
@@ -44,0 +55,0 @@ return result; |
@@ -71,2 +71,14 @@ var chai = require('chai') | ||
it("test inherits with extends parent class", function() { | ||
class B extends A1{ | ||
} | ||
inherits(B, A1) | ||
var obj = new B | ||
assert.equal(obj.inited, 'A1') | ||
assert.equal(B.super_, A1) | ||
assert.equal(B.__super__, A1.prototype) | ||
assert.equal(B.prototype.Class, B) | ||
}) | ||
it("test inherits and call super parent class", function() { | ||
@@ -73,0 +85,0 @@ class B { |
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
128281
84
2362