小编Bor*_*ris的帖子

变量绑定/第一类函数是否优于私有方法命名?吊装如何受到影响?

关于使用变量绑定与私有方法命名函数约定时构造Angular代码和JavaScript行为的一些问题.是否存在使用AngularJS中的变量绑定函数/第一类函数而不是私有方法命名的性能或风格原因?每种方法如何影响吊装?下面的第二种方法是否会减少提升量,这会对应用性能产生明显影响吗?

私有方法命名的示例.这是构建Angular代码的推荐方法吗?

    (function () {
       'use strict'
        function modalController(dataItemsService, $scope) {
            var vm = this;

            function _getSelectedItems() {
               return dataItemsService.SelectedItems();
            }

            function _deleteSelectedItems() {
               dataItemService.DeleteItem();
               $("#existConfirmDialog").modal('hide');
            }

            vm.SelectedItems = _getSelectedItems;
            vm.deleteItemRecord = _deleteItemRecord;
        }

        angular.module('app').controller('modalController', ['dataItemService', '$scope', modalController]
})();
Run Code Online (Sandbox Code Playgroud)

变量绑定函数的示例.在控制器中构造角度代码的这种方法怎么样 - 在性能/风格方面有任何缺点或优势吗?

angular.module('appname').controller("NameCtrl", ["$scope", "$log", "$window", "$http", "$timeout", "SomeService",
    function ($scope, $log, $window, $http, $timeout, TabService) {

    //your controller code
       $scope.tab = 0;    
       $scope.changeTab = function(newTab){
          $scope.tab = newTab;
       };    
       $scope.isActiveTab = function(tab){
          return $scope.tab === tab;
       }; 
    }
]);
Run Code Online (Sandbox Code Playgroud)

javascript coding-style function hoisting angularjs

2
推荐指数
1
解决办法
93
查看次数

标签 统计

angularjs ×1

coding-style ×1

function ×1

hoisting ×1

javascript ×1