Created
January 6, 2012 21:16
-
-
Save munro/1572444 to your computer and use it in GitHub Desktop.
Phredbob Inheritance
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
function algorithm(v) { | |
if (v === 0) { | |
return 'a'; | |
} else if (v === 1) { | |
return 'b'; | |
} else if (v === 2) { | |
return 'c'; | |
} | |
} | |
var tab = { | |
Hello: { | |
someMethod: function (v) { | |
if (v === 0) { | |
return false; | |
} else { | |
return algorithm(v); | |
} | |
} | |
}, | |
World: { | |
someMethod: function (v) { | |
if (v === 1) { | |
return false; | |
} else { | |
return algorithm(v); | |
} | |
} | |
} | |
}; |
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
function Base() { | |
} | |
Base.prototype.someMethod = function (v) { | |
if (v === 0) { | |
return 'a'; | |
} else if (v === 1) { | |
return 'b'; | |
} else if (v === 2) { | |
return 'c'; | |
} | |
} | |
function Hello() { | |
} | |
Hello.prototype = Object.create(Base.prototype); | |
Hello.prototype.someMethod = function (v) { | |
if (v === 0) { | |
return false; | |
} else { | |
return Base.prototype.someMethod.call(this, v); | |
} | |
}; | |
function World() { | |
} | |
World.prototype = Object.create(Base.prototype); | |
World.prototype.someMethod = function (v) { | |
if (v === 1) { | |
return false; | |
} else { | |
return Base.prototype.someMethod.call(this, v); | |
} | |
}; | |
var tab = { | |
Hello: new Hello(), | |
World: new World() | |
}; |
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 Base = Self({ | |
someMethod: function (self, v) { | |
if (v === 0) { | |
return 'a'; | |
} else if (v === 1) { | |
return 'b'; | |
} else if (v === 2) { | |
return 'c'; | |
} | |
} | |
}); | |
var Hello = Base.extend({ | |
someMethod: function (self, v) { | |
if (v === 0) { | |
return false; | |
} else { | |
return Hello.__super__.someMethod.call(self, v); | |
} | |
} | |
}); | |
var World = Base.extend({ | |
someMethod: function (self, v) { | |
if (v === 1) { | |
return false; | |
} else { | |
return World.__super__.someMethod.call(self, v); | |
} | |
} | |
}); | |
var tab = { | |
Hello: Hello(), | |
World: World() | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment