代码拉取完成,页面将自动刷新
<!--
* @Author: your name
* @Date: 2022-03-15 14:10:54
* @LastEditTime: 2022-03-17 20:54:28
* @LastEditors: Please set LastEditors
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @FilePath: \geyao\geyao\手写call220315.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>手写bind</title>
</head>
<body>
<script>
Function.prototype.mybind = function (target) {
//target:改变返回函数执行时的this指向
var obj = target || window;
console.log(arguments,"arguments")
var args = [].slice.call(arguments, 1); //获取bind时传入的绑定实参
var args1 = [].slice.call(arguments, 0); //获取bind时传入的绑定实参
console.log(args,"args")
console.log(args1,"args1")
var self = this; //要bind的函数
console.log(self,"self")
var _fn = function () {
var _args = [].slice.call(arguments, 0); //新函数执行时传递的实际参数
console.log(_args,"_args")
return self.apply(obj, args.concat(_args));
}
return _fn
}
var name = 'fangfang';
var obj = {
name: 'geyao'
};
function fn(a, b, c) {
console.log(a + b + c + this.name);
return a + b + c + this.name
};
fn.mybind(obj,"我的","老婆","是")(); // 我的老婆是geyao
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。