매우 간단합니다.이 예제에서 내 범위 작업을 수행하는 방법은 무엇입니까? 스코프의 첫 번째 참조는 갑판 기능에 기록되지만 두 번째 기록은 전역 창에 기록됩니다. 내가 원하는대로 갑판에 두 번째 참조하게하는 방법.내 javascript 범위가 잘못되었습니다.
감사합니다.
http://jsbin.com/neqevo/1/edit?js
function Deck(){
this.suits = [ // this is an array now
{
'suit': 'diamonds',
'symbol': '♦',
'color': 'red'
}
]; // close suits
this.cardValues = [
{
'name': 'ace',
'face': 'A',
'value': 1
}
]; // close cardValues
this.cards = [];
console.log(this);
this.suits.forEach(function(currentSuit){
var scope = this;
console.log(scope);
// scope doesn't work.
// obviously, scope references window
// so how do i get it to refer to the deck like it's supposed to.
// i looked into using call and apply, and even though the concepts
// made sense i couldn't figure it out.
// fuck this is frustrating!
});
}
여기에 여러 번 묻고 답했습니다. 제안 된 사본을보십시오. 나는이 작품이 어떻게 작동하고 그것이 무엇을 의미하는지 정확히 읽으시기 바랍니다. –