mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-30 05:45:44 +08:00
fix($parse): Follow JavaScript context for unbound functions
Use `undefined` as the context when a function is ounbound. E.g. when executing `foo()()`, then `foo()` is executed using the scope as the context, the function returned by `foo()` will have an `undefined` context
This commit is contained in:
@@ -709,7 +709,7 @@ Parser.prototype = {
|
|||||||
var args = argsFn.length ? [] : null;
|
var args = argsFn.length ? [] : null;
|
||||||
|
|
||||||
return function $parseFunctionCall(scope, locals) {
|
return function $parseFunctionCall(scope, locals) {
|
||||||
var context = contextGetter ? contextGetter(scope, locals) : scope;
|
var context = contextGetter ? contextGetter(scope, locals) : isDefined(contextGetter) ? undefined : scope;
|
||||||
var fn = fnGetter(scope, locals, context) || noop;
|
var fn = fnGetter(scope, locals, context) || noop;
|
||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
|
|||||||
@@ -508,11 +508,18 @@ describe('parser', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should evaluate function call from a return value', function() {
|
it('should evaluate function call from a return value', function() {
|
||||||
scope.val = 33;
|
scope.getter = function() { return function() { return 33; }; };
|
||||||
scope.getter = function() { return function() { return this.val; }; };
|
|
||||||
expect(scope.$eval("getter()()")).toBe(33);
|
expect(scope.$eval("getter()()")).toBe(33);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// There is no "strict mode" in IE9
|
||||||
|
if (!msie || msie > 9) {
|
||||||
|
it('should set no context to functions returned by other functions', function() {
|
||||||
|
scope.getter = function() { return function() { expect(this).toBeUndefined(); }; };
|
||||||
|
scope.$eval("getter()()");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
it('should evaluate multiplication and division', function() {
|
it('should evaluate multiplication and division', function() {
|
||||||
scope.taxRate = 8;
|
scope.taxRate = 8;
|
||||||
scope.subTotal = 100;
|
scope.subTotal = 100;
|
||||||
|
|||||||
Reference in New Issue
Block a user