Comparing version 2.2.1 to 2.2.2
{ | ||
"name": "herit", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"main": "herit.js" | ||
} |
@@ -35,3 +35,3 @@ (function (root, factory) { | ||
// Use Object.create if it's available. | ||
if (false && typeof Object.create === 'function') { | ||
if (herit.useObjectCreate) { | ||
Child.prototype = Object.create(Parent.prototype); | ||
@@ -60,3 +60,5 @@ | ||
herit.useObjectCreate = Object.hasOwnProperty('create'); | ||
return herit; | ||
}); |
{ | ||
"name": "herit", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"author": "Casey Foster <c@sey.me>", | ||
@@ -5,0 +5,0 @@ "main": "herit", |
var herit = require('..'); | ||
var expect = require('chai').expect; | ||
describe('A simple "class"', function () { | ||
var Klass = herit({ | ||
constructor: function () { this.instanceProp = 'a'; }, | ||
protoProp: 'b' | ||
}, { | ||
staticProp: 'c' | ||
}); | ||
[true, false].forEach(function (withObjectCreate) { | ||
describe( | ||
withObjectCreate ? 'With Object.create' : 'Without Object.create', | ||
function () { | ||
if (!withObjectCreate) { | ||
before(function () { herit.useObjectCreate = false; }); | ||
} | ||
it('is a function', function () { | ||
expect(Klass).to.be.a('function'); | ||
}); | ||
describe('A simple "class"', function () { | ||
var Klass = herit({ | ||
constructor: function () { this.instanceProp = 'a'; }, | ||
protoProp: 'b' | ||
}, { | ||
staticProp: 'c' | ||
}); | ||
it('is inherited by its child', function () { | ||
expect(new Klass()).to.be.instanceof(Klass); | ||
}); | ||
it('is a function', function () { | ||
expect(Klass).to.be.a('function'); | ||
}); | ||
it('copies static properties', function () { | ||
expect(Klass).to.have.property('staticProp', 'c'); | ||
}); | ||
it('is inherited by its child', function () { | ||
expect(new Klass()).to.be.instanceof(Klass); | ||
}); | ||
it('copies prototype properties', function () { | ||
expect(Klass.prototype).to.have.property('protoProp', 'b'); | ||
}); | ||
it('copies static properties', function () { | ||
expect(Klass).to.have.property('staticProp', 'c'); | ||
}); | ||
it('equals the special constructor property', function () { | ||
expect(Klass.prototype.constructor).to.equal(Klass); | ||
}); | ||
it('copies prototype properties', function () { | ||
expect(Klass.prototype).to.have.property('protoProp', 'b'); | ||
}); | ||
it('invokes the constructor on instance creation', function () { | ||
expect(new Klass()).to.have.property('instanceProp', 'a'); | ||
}); | ||
}); | ||
it('equals the special constructor property', function () { | ||
expect(Klass.prototype.constructor).to.equal(Klass); | ||
}); | ||
describe('Single inheritance', function () { | ||
var KlassA = herit({ | ||
aProtoMethod: function () {} | ||
}, { | ||
aStaticMethod: function () {} | ||
}); | ||
it('invokes the constructor on instance creation', function () { | ||
expect(new Klass()).to.have.property('instanceProp', 'a'); | ||
}); | ||
}); | ||
var KlassB = herit(KlassA); | ||
describe('Single inheritance', function () { | ||
var KlassA = herit({ | ||
aProtoMethod: function () {} | ||
}, { | ||
aStaticMethod: function () {} | ||
}); | ||
it('works with instanceof', function () { | ||
expect(new KlassB()).to.be.instanceOf(KlassA); | ||
}); | ||
var KlassB = herit(KlassA); | ||
it("inherits the parent class's static methods", function () { | ||
expect(KlassB).to.have.property('aStaticMethod'); | ||
}); | ||
it('works with instanceof', function () { | ||
expect(new KlassB()).to.be.instanceOf(KlassA); | ||
}); | ||
it("inherits the parent class's prototype methods", function () { | ||
expect(KlassB.prototype).to.have.property('aProtoMethod'); | ||
}); | ||
}); | ||
it("inherits the parent class's static methods", function () { | ||
expect(KlassB).to.have.property('aStaticMethod'); | ||
}); | ||
describe('Multiple inheritance', function () { | ||
var KlassA = herit({ | ||
theProtoMethod: function () {} | ||
}); | ||
it("inherits the parent class's prototype methods", function () { | ||
expect(KlassB.prototype).to.have.property('aProtoMethod'); | ||
}); | ||
}); | ||
var KlassB = herit({ | ||
theProtoMethod: function () {} | ||
}); | ||
describe('Multiple inheritance', function () { | ||
var KlassA = herit({ | ||
theProtoMethod: function () {} | ||
}); | ||
var KlassC = herit(KlassA, KlassB); | ||
var KlassB = herit({ | ||
theProtoMethod: function () {} | ||
}); | ||
it('works with instanceof', function () { | ||
expect(new KlassC()).to.be.instanceOf(KlassA).and.instanceOf(KlassB); | ||
}); | ||
var KlassC = herit(KlassA, KlassB); | ||
it("inherits the most recent parent class's prototype methods", function () { | ||
expect(KlassC.prototype).to.have | ||
.property('theProtoMethod', KlassB.prototype.theProtoMethod); | ||
}); | ||
it('works with instanceof', function () { | ||
expect(new KlassC()).to.be.instanceOf(KlassA).and.instanceOf(KlassB); | ||
}); | ||
it("inherits the most recent parent's prototype methods", function () { | ||
expect(KlassC.prototype).to.have | ||
.property('theProtoMethod', KlassB.prototype.theProtoMethod); | ||
}); | ||
}); | ||
} | ||
); | ||
}); |
Sorry, the diff of this file is not supported yet
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
28018
126