Skip to content

Instantly share code, notes, and snippets.

@veer66
Last active December 22, 2015 19:19
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 veer66/6519244 to your computer and use it in GitHub Desktop.
Save veer66/6519244 to your computer and use it in GitHub Desktop.
ท่าใช้ factory function อะ ( อาจจะมั่ว ไม่ได้ลอง run )
fucntion createDog(name, owner) {
var dog = {
name: name,
owner: owner,
init: function() {
var me = $('<button>').addClass('dog').append(this.name).click(this.bark);
$('#animals').append(me);
},
bark: function() {
alert(this.name + ': Bark bark. I love you, ' + this.owner + '. Bark!');
}
}
dog.init();
return dog;
}
// http://neizod.blogspot.com/2013/09/coffeescript-scope.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment