Last active
August 29, 2015 14:05
-
-
Save hejrobin/03252819c5505574543e to your computer and use it in GitHub Desktop.
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 Person | |
constructor: (@name) -> | |
goodGreet: => | |
"Hello, my name is #{@name}" | |
badGreet: -> | |
"I'm #{@name} and this won't work!" | |
pewpewpew = (callback) -> | |
console.log callback() | |
person = new Person('Slartibartfast') | |
pewpewpew person.goodGreet() # @name blir "Slartibartfast" | |
pewpewpew person.badGreet() # @name blir "result" |
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 Person, person, pewpewpew, | |
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | |
Person = (function() { | |
function Person(name) { | |
this.name = name; | |
this.goodGreet = __bind(this.goodGreet, this); | |
} | |
Person.prototype.goodGreet = function() { | |
return "Hello, my name is " + this.name; | |
}; | |
Person.prototype.badGreet = function() { | |
return "I'm " + this.name + " and this won't work!"; | |
}; | |
return Person; | |
})(); | |
pewpewpew = function(callback) { | |
return console.log(callback()); | |
}; | |
person = new Person('Slartibartfast'); | |
pewpewpew(person.goodGreet()); | |
pewpewpew(person.badGreet()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment