I used a strange way to add a callback function to my actions and I was wondering if there was any more common way To add a callback to the function, in the best condition I would have a situation where all of my function functions are checked to get the last given ultimate and if so, use it as a callback.
In the same way I past it:
var myFunc = function (obj) {if (arguments.length & gt; 0) {if (_.util.typeofObj Logic [arguments.length-1]) === function) {var callback = arguments [arguments. Lanti-1]; }} // some code ... if (callback! == undefined) {callback (); }}; Var foo = myFunc (myObj, function () {warning ('callback!');}); Any suggestions?
If you really want to, function with a .cb prototype. Expansion of prototype Please. Something like this:
function.prototype CB = function (CB) {var itself = this; Return work () {self.callback = cb || Function () {}; Self. Aply (self, logic); }} Then your code will be compressed:
var myFunc = function (obj) {// some code this.callback (); // callback will always be defined} and the call will change a bit:
myFunc.cb (function () {// callback code}) ( MyObj); Just one thought, you can create as many syntax as you want.
Comments
Post a Comment