From fef7bffad8e74503022b1755f2fddb0cb0c1cb4a Mon Sep 17 00:00:00 2001 From: NONI <1063030602@qq.com> Date: Mon, 13 Nov 2023 23:27:07 +0800 Subject: [PATCH] fix --- .../\346\211\213\345\206\231call.md" | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git "a/docs/\351\235\242\350\257\225/NONI/JS/JS\345\237\272\347\241\200/\346\211\213\345\206\231call.md" "b/docs/\351\235\242\350\257\225/NONI/JS/JS\345\237\272\347\241\200/\346\211\213\345\206\231call.md" index 849362a..dd7a74a 100644 --- "a/docs/\351\235\242\350\257\225/NONI/JS/JS\345\237\272\347\241\200/\346\211\213\345\206\231call.md" +++ "b/docs/\351\235\242\350\257\225/NONI/JS/JS\345\237\272\347\241\200/\346\211\213\345\206\231call.md" @@ -1,3 +1,10 @@ +### **call()** + +调用call的函数挂载到传入的第一个参数上,再通过该参数对象来调用‘调用call的函数’,并且能够得到传入其他参数后执行得到的结果 + +例如:Fn.call(context, a,b),函数Fn挂载到context对象上,通过context对象调用函数Fn,并且能够得到传入参数a,b后执行得到的结果 + +### **手写** ```js Function.prototype.myCall = function (context) { if (context === null || context === undefined) { @@ -53,4 +60,15 @@ fn1.myCall(1, 1, 2); fn1.myCall("str", 1, 2); fn1.myCall(true, 1, 2); - ``` \ No newline at end of file +``` + +### **简单版本** + +```js +Function.prototype.myCall = function(context){ + context.fn = this + context.fn(); + delete context.fn +} + +``` \ No newline at end of file