I'm using the javascript revealing prototype pattern, and I want to add a callback. I'm trying something like:
http://jsfiddle.net/Qyhrb/2/
var Refinements = function () { };
Refinements.prototype = function () {
Init = function () {
$('.btn').click(Callback);
},
Callback = function(){
alert('default function');
};
return { Init: Init, Callback : Callback };
}();
var refinements = new Refinements();
refinements.Callback = function(){ alert('new method'); };
refinements.Init();
Essentially what I want to do is pass a callback into the object and raise that callback when an event occurs.
Init = function () {
var refinement = this;
$('.btn').click(refinement.Callback || Callback);
},
Fiddle
var Refinements = function() {};
Refinements.prototype = function() {
return {
init: function() {
$('.btn').click(this.callback);
},
callback: function() {
alert('default function');
}
}
}();
var refinements = new Refinements();
refinements.callback = function() {
alert('new method');
};
refinements.init();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With