2017-07-26 8 views
0

私はJavascriptとOpenUI5を初めて使用しています。 私は以下のコードを来たopenUi5サイトOpenUI5 walkthrough demothis._helloDialog in OpenUI5 walkthrough

にウォークスルーデモを通過した_helloDialogが定義され、我々はされていない場合、私はラインthis._helloDialog = new HelloDialog(this.getRootControl());

に疑問を持っている

sap.ui.define([ 
    "sap/ui/core/UIComponent", 
    "sap/ui/model/json/JSONModel", 
    "sap/ui/demo/wt/controller/HelloDialog" 

], function (UIComponent, JSONModel, HelloDialog) { 
    "use strict"; 
    return UIComponent.extend("sap.ui.demo.wt.Component", { 
     metadata : { 
      manifest : "json" 
     }, 
     init : function() { 
      // call the init function of the parent 
      UIComponent.prototype.init.apply(this, arguments); 
      // set data model 
      var oData = { 
       recipient : { 
        name : "World" 
       } 
      }; 
      var oModel = new JSONModel(oData); 
      this.setModel(oModel); 

      // set dialog 
      this._helloDialog = new HelloDialog(this.getRootControl()); 
     }, 

     openHelloDialog : function() { 
      this._helloDialog.open(); 
     } 
    }); 
}); 

厳格なモードを使用すると、システムはなぜ_helloDialog is undefinedというメッセージを投げないのですか?

答えて

1

_helloDialogは、this(コントローラ)のプロパティであり、オブジェクトを作成するときにプロパティを初期化する必要はありません。

"use strict" 
 
var example = {}; 
 
example.newProperty = "i am a new property"; //This is absolutely correct 
 

 
undefinedVariable = 1; // This is going to throw an error

厳格モードが(undefinedVariable = 1;として行うだろう)、暗黙的にグローバル変数を作成できません。しかし、オブジェクトへのプロパティの追加を防ぐことはできません。

プロパティの作成を防止することに興味がある場合は、私は読むことをお勧めします。Freeze vs Seal

関連する問題