在读《JavaScript设计模式》的时候对这段代码有个疑问?

书中讲单体模式用了这段代码。我的问题是在对象内部访问对象的属性时为何没有用this.foo而依然用GiantCorp.RegPage.foo
GiantCorp.RegPage={
//Constants.
FORM_ID:'reg-form',
OUTPUT_ID:'reg-results',
//Formhandlingmethods.
handleSubmit:function(e){
e.preventDefault();//Stopthenormalformsubmission.
vardata={};
varinputs=GiantCorp.RegPage.formEl.getElementsByTagName('input');
//Collectthevaluesoftheinputfieldsintheform.
for(vari=0,len=inputs.length;idata[inputs[i].name]=inputs[i].value;
}
//Sendtheformvaluesbacktotheserver.
GiantCorp.RegPage.sendRegistration(data);
},
sendRegistration:function(data){
//MakeanXHRrequestandcalldisplayResult()whentheresponseis
//received.
...
},
displayResult:function(response){
//Outputtheresponsedirectlyintotheoutputelement.Weare
//assumingtheserverwillsendbackformattedHTML.
GiantCorp.RegPage.outputEl.innerHTML=response;
},
//Initializationmethod.
init:function(){
//Gettheformandoutputelements.
GiantCorp.RegPage.formEl=$(GiantCorp.RegPage.FORM_ID);
GiantCorp.RegPage.outputEl=$(GiantCorp.RegPage.OUTPUT_ID);
//Hijacktheformsubmission.
addEvent(GiantCorp.RegPage.formEl,'submit',GiantCorp.RegPage.handleSubmit);
}
};
//Invoketheinitializationmethodafterthepageloads.
addLoadEvent(GiantCorp.RegPage.init);
慕码人2483693
浏览 291回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript