Skip to content

Instantly share code, notes, and snippets.

View Raynos's full-sized avatar

Jake Verbaten Raynos

View GitHub Profile
@Raynos
Raynos / pd.js
Created October 11, 2011 08:46
Node vanilla REST server
/*
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);
// classical
var Foo = function _construct(a) {
this.a = a;
}
Foo.prototype.lulz = function () {};
Foo.prototype.prop = 42;
// new
var Foo = {
// 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;
// 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"),
magic.Extend({
foo: {
bar: {
baz: true
}
}
}, {
"foo.bar.bas": true
}) === {
foo: {
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();
// Create base prototype
var Base = {
method: function () {
return this.things;
},
constructor: function (things) {
this.things = things;
}
};
// Link constructor and prototype
var Proto = {
prop: 42,
method: function () {
return this.thing;
},
constructor: function (thing) {
this.thing = thing;
}
};
// 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";
}
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;
}
}
};