如何使用装饰没有访问object.defineProperty?AngularJS装饰没有object.defineProperty
我期待到可用的垫片:
但如果那些没有通过测试,有没有装修的目的是要工作的另一种方式?
我使用的装饰工具为$onRootScope。
我使用角度1.08。我需要与IE7兼容。
更新
我已经试过了,似乎工作的一些方法,但我不知道他们之间的区别是:plunkr
var app = angular.module('plunker', []);
app.config(['$provide', function($provide){
$provide.decorator('$rootScope', ['$delegate', function($delegate){
$delegate.a = 1;
$delegate.constructor.prototype.b = 2;
Object.defineProperty($delegate.constructor.prototype, 'c', {
value: 3
});
return $delegate;
}]);
}]);
app.controller('MainCtrl', function($rootScope, $scope) {
console.log($rootScope); //reveals `a` property
console.log($rootScope.constructor.prototype); //=> {b:2, c:3}
console.log($rootScope.a); //=> 1
console.log($rootScope.b); //=> 2
console.log($rootScope.c); //=> 3
$scope.name = 'World';
});
谢谢。
哟可以给你为什么认为你是被迫使用Object.defineProperty一个实例通过$ onRootScope创建一个装饰器? –
@EdwinDalorzo它已经在问题了。我提到了如何定义$ onRootScope并使用'object.defineProperty()'的答案。我发现的其他例子也使用它。你有没有*不使用'object.defineProperty()'的例子? –