我正在使用forEach
函数遍历一个简单的对象,我将该对象作为上下文传递。
当我尝试使用this[key]
访问对象属性时,它起作用但this.key
不起作用,有人可以告诉我们为什么它会如此吗?
var calendar = {
moveAll: false,
moveSingleDay: false,
translateRange : false
}
angular.forEach(calendar, function(val, key){
console.log(this[key]); // returns val
console.log(this.key); // returns undefined
}, calendar);
最佳答案
this.key
等效于this['key']
。
关于javascript - 使用angularjs forEach的this.key和this [key]之间的区别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34608783/