call(thisArg, arg1, aeg2, …)
把需要改变this指向的方法挂载到目标this上执行并返回
调用一个对象的方法,以另一个对象替换当前对象,如果没有就用Global对象替换
参数:
- thisArg 当要被用作当前对象的对象
- arg1, aeg2, … 要传入方法的参数
1
2
3
4
5
6
7
8
9
10Function.prototype.mycall = function(context=window){
if ( typeof this != 'function' ){
throw new TypeError('not function')
}
context.fn = this
var args = [...arguments].slice(1)
var results = context.fn(...args)
delete context
return results
}
1 |
//demo1 |
apply(thisArg, […])
调用一个对象的方法,以一个对象替换当前对象,(同call,只是参数不一样)
1 |
Function.prototype.myapply = function(context){ |
bind(thisArg,…)
1 |
Function.prototype.mybind = function(context){ |
instanceof
右边变量的原型存在于左边变量的原型链上
1 |
function(left, right){ |
Object.create
将传入对象作为原型
1 |
function create(obj){ |




近期评论