JavaScript call,apply,bind 的用法区别

2023-12-22 09:46:03
var obj = {
    name:"一个"
}

function say(firstName,secondName,flag) {
    console.log(`${firstName}${this.name}${secondName},座右铭是:${flag}`);
}

say.call(obj,"我是","前端","no bug no erro!")
say.apply(obj,["我是","前端","no bug no erro!"])

var fn=say.bind(obj)
fn("我是","前端","no bug no erro!")
var fn2=say.bind(obj,"你是")
fn2("前端","no bug no erro!")

// 生成一个随机数
console.log(Math.random().toString(32).slice(2));

文章来源:https://blog.csdn.net/thankseveryday/article/details/135144506
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。