This file contains hidden or 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
/* | |
A utility function to turn an object into a property descriptor hash | |
@param Object obj - the Object of keys & values to turn into an object of | |
keys and PropertyDescriptor(value) | |
*/ | |
var pd = function _pd (obj) { | |
var o = {}; | |
Object.keys(obj).forEach(function (key) { | |
var pd = Object.getOwnPropertyDescriptor(obj, key); |
This file contains hidden or 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
// classical | |
var Foo = function _construct(a) { | |
this.a = a; | |
} | |
Foo.prototype.lulz = function () {}; | |
Foo.prototype.prop = 42; | |
// new | |
var Foo = { |
This file contains hidden or 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
// require("pd").extendNatives(); | |
// - https://github.com/Raynos/pd | |
var SuperStar = { | |
constructor: function _constructor() { | |
this._fans = []; | |
}, | |
addFan: function _addFan(fan) { | |
this._fans.push(fan); | |
return this; |
This file contains hidden or 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
// set up pd | |
var pd = require("pd").extendNatives(); | |
// dependencies and unpacking frame | |
var arch = require("arch"), | |
error = arch.error, | |
fs = require("fs"), | |
Arch = arch.Arch, | |
http = require("http"), | |
path = require("path"), |
This file contains hidden or 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
magic.Extend({ | |
foo: { | |
bar: { | |
baz: true | |
} | |
} | |
}, { | |
"foo.bar.bas": true | |
}) === { | |
foo: { |
This file contains hidden or 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 stack = new Stack( | |
function (path) { | |
// default return value | |
this.return = path; | |
// after three actions | |
var cb = after(3, (function (a,b,c) { | |
// if all succeed go next | |
if (a && b && c) { | |
this.next(); |
This file contains hidden or 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
// Create base prototype | |
var Base = { | |
method: function () { | |
return this.things; | |
}, | |
constructor: function (things) { | |
this.things = things; | |
} | |
}; | |
// Link constructor and prototype |
This file contains hidden or 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 Proto = { | |
prop: 42, | |
method: function () { | |
return this.thing; | |
}, | |
constructor: function (thing) { | |
this.thing = thing; | |
} | |
}; |
This file contains hidden or 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
// But I don't want a direct reference to the Parent class in my code!! | |
var super = function (obj) { | |
return Object.getPrototypeOf(obj); | |
} | |
var Child = Object.create(Parent); | |
Child.hierachy = function () { | |
return super(this).hierachy.call(this) + " < C"; | |
} |
This file contains hidden or 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 punchSuper($super, klas) { | |
var keys = Object.keys(klas); | |
for (var i = 0, len = keys.length; i < len; i++) { | |
var val = keys[i]; | |
if (typeof val === "function") { | |
val.$super = $super; | |
} | |
} | |
}; |