小编iks*_*ose的帖子

使用setter方法的JavaScript属性不是真正的属性吗?

function Name(first, last) {
  this.first = first;
  this.last = last;
  this.fullName = first + " " + last
}

Name.prototype = {
  get fullName() {
    return this.first + " " + this.last;
  },

  set fullName(name) {
    var names = name.split(" ");
    this.first = names[0];
    this.last = names[1];
  }
};

var person = new Name("Foo", "Bar");
// person.fullName = "Foo Bar"
person.hasOwnProperty("fullName") // false
Run Code Online (Sandbox Code Playgroud)

有办法归还物业吗?

javascript inheritance

8
推荐指数
2
解决办法
251
查看次数

Angular2 DI与ES2016装饰器?

这是我在github上最接近的

我的服务是

@Injectable() export class TodoService {}

但我不确定如何使用ES2016装饰器将其注入我的组件.它甚至是可能的,还是装饰器特定于原型?我知道TS有一个emitDecoratorMetadata选择.

ecmascript-7 angular

5
推荐指数
1
解决办法
261
查看次数

我是否滥用过多逻辑的指令?

假设我从a获取了一个对象列表factory,将其传递给a controller,并从那里渲染出来directive......到目前为止,这是最佳实践,对吧?

假设每个对象都有一个save()函数,如果我的指令如下:

.directive('Foo', function($modal) {
    return {
        restrict: 'EA',
        require: 'ngModel',
        transclude: true,
        templateUrl: 'admin/foo.html',
        scope: {
            model: '=ngModel',
            save: '&'
        },
        controller: function($scope) {
            $scope.$watch('model', function(newVal, oldVal) {
                init()
            });
            function init(){
              // do some loops
            };
            $scope.doThis(){
             // click event
            }
           $scope.checkThat(){
             // some array methods
            }
           $scope.proxySave(){
             // call passed in fn();
             $scope.save({})
            }
        },
        link: function(scope, element, attr, ngModel) {
          // not really doing much here
        }
Run Code Online (Sandbox Code Playgroud)

从指令html开始,将会有一些定义为ng-click的函数 …

angularjs

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