Created
December 7, 2011 02:07
-
-
Save Raynos/1441105 to your computer and use it in GitHub Desktop.
The heart of pd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Parent = { | |
constructor: function constructor(magic) { | |
this.isMagic = magic | |
return this | |
}, | |
method: function method() { } | |
} | |
var Mixin = { | |
mixinMethod: function () { } | |
} | |
var Child = extend({}, Parent, Mixin, { | |
constructor: function constructor(magic, count) { | |
this.count = count | |
return Parent.constructor.call(this, magic) | |
}, | |
anotherMethod: function () { } | |
}) | |
var instance = extend({}, Child).constructor(true, 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var slice = Array.prototype.slice; | |
function extend(object) { | |
slice.call(arguments, 1).forEach(copyProperties); | |
return object; | |
function copyProperties(source) { | |
Object.getOwnPropertyNames(source).forEach(copyProperty); | |
function copyProperty(name) { | |
object[name] = source[name]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment