Skip to content

Instantly share code, notes, and snippets.

@hejrobin
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hejrobin/03252819c5505574543e to your computer and use it in GitHub Desktop.
Save hejrobin/03252819c5505574543e to your computer and use it in GitHub Desktop.
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"
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