Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created December 7, 2011 02:07
Show Gist options
  • Save Raynos/1441105 to your computer and use it in GitHub Desktop.
Save Raynos/1441105 to your computer and use it in GitHub Desktop.
The heart of pd
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)
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