var test = { init: function () { var data = $rootScope.test; if(data) { …… this.method(data); } }, method: function (data) { console.log(data); }};還是var test = { data: $rootScope.test, init: function () { if(this.data) { …… this.method(); } }, method: function () { console.log(this.data); }};哪種方式是最佳實踐如果第一種方式要傳遞的層級過多怎么辦 比如開始是 init 調 method 傳過去 之后有 method[n] 種 執行順序是 init -> method -> method2 -> method3 這樣的 要一級一級傳嗎……還有就是兩種方法那種性能高些呢 第二種每次取值都相當于取對象的屬性 表象上直接傳參性能會跟憂些?~
方法要用到一個外部的數據 那么是優先選擇當成參數傳過去 還是把數據存成相對當前作用域來說全局的變量~
慕桂英4014372
2018-11-13 17:35:13
