异步,传入的函数在重绘以前调用html
冒泡vue
Function.prototype.a = 'a'; Object.prototype.b = 'b'; function Person(){}; var p = new Person(); console.log('p.a: '+ p.a); // p.a: undefined console.log('p.b: '+ p.b); // p.b: b ps: //Object.prototype就是实例 是全被继承的
const person = { namea: 'menglinghua', say: function (){ return function (){ console.log(this.namea); }; } }; person.say()(); // undefined
const person = { namea: 'menglinghua', say: function (){ return () => { console.log(this.namea); }; } }; person.say()(); // menglinghua
setTimeout(() => console.log('a'), 0); var p = new Promise((resolve) => { console.log('b'); resolve(); }); p.then(() => console.log('c')); p.then(() => console.log('d')); console.log('e'); // 结果:b e c d a // 任务队列优先级:promise.Trick()>promise的回调>setTimeout>setImmediate
async function async1() { console.log("a"); await async2(); //执行这一句后,await会让出当前线程,将后面的代码加到任务队列中,而后继续执行函数后面的同步代码 console.log("b"); } async function async2() { console.log( 'c'); } console.log("d"); setTimeout(function () { console.log("e"); },0); async1(); new Promise(function (resolve) { console.log("f"); resolve(); }).then(function () { console.log("g"); }); console.log('h'); // 谁知道为啥结果不同????????????? // 直接在控制台中运行结果: d a c f h g b e // 在页面的script标签中运行结果:d a c f h b g e
function bind(fn, context){ return function (){ return fn.apply(context, arguments); } }
ps:promise
http://www.cnblogs.com/yuri2016/p/6542625.html浏览器