topic description
Thefunction asyncify is a function whose output is the same regardless of whether it is called asynchronously or called by Synchronize (in this case, a = 1). The judgment about Synchronize does not quite understand the logical meaning of it, especially the statement [this] .concat ([] .slice.call (arguments). The book explains that this is called currying, later, which roughly means that parameters can be passed in succession. Later, I still didn"t understand this sentence
.sources of topics and their own ideas
A case study of the callback chapter in the book "JavaScript you don"t know"
related codes
function asyncify(fn) {
var orig_fn = fn,
intv = setTimeout(function () {
intv = null;
if (fn) fn();
}, 0);
console.log("Wai intv:"+intv);
fn = null;
return function () {
console.log("Nei intv:"+intv);
if (intv) {
//
fn = orig_fn.bind.apply(
orig_fn,
// thisbind(..)
// currying
[this].concat([].slice.call(arguments))
);
} else {
//
orig_fn.apply(this, arguments);
}
};
}
function result(data) {
console.log(a);
}
var a = 0;
var b = asyncify(result);
aPP;
what result do you expect? What is the error message actually seen?
1