Is it possible to wrap functions like setTimeout and then fire callback. Like in jQuery $(selector).on('action', callback).
var obj = {
mth1: function (callback) {
//----need to wrap to something
setTimeout(function () { console.log("1"); }, 1000);
console.log('2');
//----
// callback;
}
};
function callback() {
console.log('3');
};
(function () { obj.mth1(callback); }) ();
What I need:
2
1
3
callback()afterconsole.log(1)in thesetTimeoutfunction?