-
-
Save zacksleo/8571055 to your computer and use it in GitHub Desktop.
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
| (function() { | |
| var core = { | |
| require : function(source) { | |
| if ( typeof (source) != "object" || !source) | |
| throw new TypeError("Object needed as source."); | |
| for (var property in source) | |
| if (source.hasOwnProperty(property) && !this.prototype.hasOwnProperty(property)) | |
| this.prototype[property] = source[property]; | |
| }, | |
| override : function(source) { | |
| if ( typeof (source) != "object" || !source) | |
| throw new TypeError("Object needed as source."); | |
| for (var property in source) | |
| if (source.hasOwnProperty(property)) | |
| this.prototype[property] = source[property]; | |
| }, | |
| extend : function(source) { | |
| var superClass = this; | |
| var newClass = source.hasOwnProperty("constructor") ? source.constructor : function() { | |
| superClass.apply(this, arguments); | |
| }; | |
| newClass.superClass = superClass; | |
| var superClone = function() { | |
| }; | |
| superClone.prototype = superClass.prototype; | |
| newClass.prototype = new superClone(); | |
| newClass.prototype.constructor = newClass; | |
| if (source) | |
| newClass.override(source); | |
| return newClass; | |
| } | |
| }; | |
| core.require.call(Function, core); | |
| Function.create = function (source){ | |
| var newClass = source.hasOwnProperty("constructor") ? source.constructor : function() {}; | |
| newClass.override(source); | |
| return newClass; | |
| }; | |
| })(); | |
| var Vehicle = Function.create({ | |
| constructor : function(wheels) { | |
| this.wheels = wheels; | |
| } | |
| }); | |
| var Truck = Vehicle.extend({ | |
| constructor : function(hp, wheels) { | |
| this.horsepower = hp; | |
| Vehicle.call(this, wheels); | |
| }, | |
| printInfo : function() { | |
| console.log('I am a truck and I have ' + this.horsepower + ' hp.'); | |
| } | |
| }); | |
| var t = new Truck(4, 350); | |
| t.printInfo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment