题解 | #模块#
模块
https://www.nowcoder.com/practice/48e53feaabe94506a61300edadb5496d
思路:this。
function createModule(str1, str2) { return { 'greeting':str1, 'name':str2, sayIt(){ return this.greeting+', '+this.name } } }
总结:注意,箭头函数没有this。如果把sayIt写成箭头函数,那么内部的this就会变成其所在作用域的调用者,而对象的大括号不算做作用域,故就变成了window,就会出错。
#模块#前端js面试 文章被收录于专栏
前端js面试,帮助你更好的理解js。