书中讲单体模式用了这段代码。我的问题是在对象内部访问对象的属性时为何没有用this.foo而依然用GiantCorp.RegPage.fooGiantCorp.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);
相关分类