我正在通过这个doc,我的困惑是link.apply(this,attrs)中的'this'是什么。有人可以帮忙吗?角装饰者中的'this'是什么?
$provide.decorator('fooDirective', function($delegate) {
var directive = $delegate[0];
directive.scope.fn = "&";
var link = directive.link;
directive.compile = function() {
return function(scope, element, attrs) {
link.apply(this, arguments);
element.bind('click', function() {
scope.$apply(function() {
scope.fn();
});
});
};
};
return $delegate;
});
});
当我尝试使用控制台调试程序进行调试时,'this'在链接函数运行时未定义。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply – Sai