Skip to content

Instantly share code, notes, and snippets.

@rightjs
Created May 27, 2010 05:48
Show Gist options
  • Save rightjs/415511 to your computer and use it in GitHub Desktop.
Save rightjs/415511 to your computer and use it in GitHub Desktop.
// you could use the shared module feature
var SharedModule = {
callback: function() {
/// ....
}
};
var Dog = new Class({
include: SharedModule,
bark: function() {
....
}
});
var dog = new Dog();
// but in reality you don't need all those,
// there is a method called 'bind' for functions
$('element').onClick(dog.bark.bind(dog));
// check this tutorial http://rightjs.org/tutorials/functional-programming
// then if you'll try RightJS from master,
// you can prebind your methods automatically like that
var Dog = new Class({
prebind: ['bark']
bark: function() {
}
});
var dog = new Dog();
$('element').onClick(dog.bark);
// and finally RightJS has a shortctut
$A(arguments);
// which is the same as
Array.prototype.slice.call(arguments);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment