文本描述
2019/9/5 第?部分:进阶篇 | FE-Interview JS b() // call b console.log(a) // undefined var a = Hello world function b() { console.log(call b) } JS undefined b() // call b second function b() { console.log(call b fist) } function b() { blog.poetries.top/FE-Interview-Questions/improve/#?、js 1/27 2019/9/5 第?部分:进阶篇 | FE-Interview console.log(call b second) } var b = Hello world var let let let let call apply this call apply let a = { value: 1 } function getValue(name, age) { console.log(name) console.log(age) console.log(this.value) } getValue.call(a, yck, 24) getValue.apply(a, [yck, 24]) bind bind window this blog.poetries.top/FE-Interview-Questions/improve/#?、js 2/27 2019/9/5 第?部分:进阶篇 | FE-Interview Function.prototype.myBind = function (context) { if (typeof this !== function) { throw new TypeError(Error) } var _this = this var args = [...arguments].slice(1) // return function F() { // new F() if (this instanceof F) { return new _this(...args, ...arguments) } return _this.apply(context, args.concat(...arguments)) } } Function.prototype.myCall = function (context) { var context = context || window // context // getValue.call(a, yck, 24) => a.fn = getValue context.fn = this // context var args = [...arguments].slice(1) // getValue.call(a, yck, 24) => a.fn(yck, 24) var result = context.fn(...args) // fn delete context.fn return result } Function.prototype.myApply = function (context) { var context = con