关于this
来源:8-15 【连环问】手写函数call和apply功能

慕丝3211513
2022-03-05
老师可以详细解释一下这两行代码吗,为什么这样写this就挂在content身上了呀,如果不同Symbol该怎么写呢
写回答
1回答
-
// 定义 Symbol ,每个 symbol 值都是唯一的,无论穿不穿字符串 const s1 = Symbol() const s2 = Symbol() const s3 = Symbol('a') // symbol 可以作为 object 的属性 key const obj = {} obj[s1] = 100 obj[s2] = 'hello' obj[s3] = function () { } // 获取属性 const num = obj[s1] const str = obj[s2] // 执行函数 obj[s3]()
这样分析你能明白了吧?
012022-03-06
相似问题