我正在通過這個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