Created
July 15, 2014 18:05
-
-
Save meeDamian/7f144956618d301356dc to your computer and use it in GitHub Desktop.
Random extend example
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
class Orange extends Fruit | |
constructor: -> | |
console.log 'Orange created' | |
peel: -> | |
console.log 'Oh god, that hurts' | |
orange = new Orange() | |
orange.peel() |
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 Orange, orange, | |
__hasProp = {}.hasOwnProperty, | |
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | |
Orange = (function(_super) { | |
__extends(Orange, _super); | |
function Orange() { | |
console.log('Orange created'); | |
} | |
Orange.prototype.peel = function() { | |
return console.log('Oh god, that hurts'); | |
}; | |
return Orange; | |
})(Fruit); | |
orange = new Orange(); | |
orange.peel(); |
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 util = require('util'); | |
var Orange = function() { | |
console.log('Orange created'); | |
}; | |
util.inherits(Orange, Fruit); | |
Orange.prototype.peel = function() { | |
console.log('Oh god, that hurts'); | |
}; | |
var orange = new Orange(); | |
orange.peel(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment