diff options
| -rw-r--r-- | src/Angular.js | 18 | ||||
| -rw-r--r-- | src/Compiler.js | 4 | ||||
| -rw-r--r-- | src/Scope.js | 9 | ||||
| -rw-r--r-- | test/ScopeSpec.js | 8 |
4 files changed, 23 insertions, 16 deletions
diff --git a/src/Angular.js b/src/Angular.js index 404d241d..850fe34c 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -16,7 +16,7 @@ var consoleNode, msie = !!/(msie) ([\w.]+)/.exec(lowercase(navigator.userAgent)), jqLite = jQuery || jqLiteWrap, slice = Array.prototype.slice, - error = window['console'] ? bind(window['console'], window['console']['error']) : noop, + error = window['console'] ? bind(window['console'], window['console']['error'] || noop) : noop, angular = window['angular'] || (window['angular'] = {}), angularTextMarkup = extensionMap(angular, 'textMarkup'), angularAttrMarkup = extensionMap(angular, 'attrMarkup'), @@ -292,12 +292,14 @@ function escapeAttr(html) { } function bind(_this, _function) { - if (!isFunction(_function)) - throw "Not a function!"; var curryArgs = slice.call(arguments, 2, arguments.length); - return function() { - return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length))); - }; + return curryArgs.length == 0 ? + function() { + return _function.apply(_this, arguments); + } : + function() { + return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length))); + }; } function outerHTML(node) { @@ -331,12 +333,12 @@ function merge(src, dst) { } } -function compile(element, parentScope, overrides) { +function compile(element, parentScope) { var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget), $element = jqLite(element), parent = extend({}, parentScope); parent.$element = $element; - return compiler.compile($element)($element, parent, overrides); + return compiler.compile($element)($element, parent); } ///////////////////////////////////////////////// diff --git a/src/Compiler.js b/src/Compiler.js index a6fd88ec..bcf1f61a 100644 --- a/src/Compiler.js +++ b/src/Compiler.js @@ -30,7 +30,9 @@ Template.prototype = { element = jqLite(element); foreach(this.inits, function(fn) { queue.push(function(scope) { - scope.$tryEval(fn, element, element); + scope.$tryEval(function(){ + return fn.call(scope, element); + }, element); }); }); diff --git a/src/Scope.js b/src/Scope.js index 549cc944..6b011936 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -131,7 +131,7 @@ function createScope(parent, services, existing) { $eval: function $eval(exp) { if (exp !== undefined) { - return expressionCompile(exp).apply(instance, slice.call(arguments, 1, arguments.length)); + return expressionCompile(exp).call(instance); } else { for ( var i = 0, iSize = evalLists.sorted.length; i < iSize; i++) { for ( var queue = evalLists.sorted[i], @@ -145,7 +145,7 @@ function createScope(parent, services, existing) { $tryEval: function (expression, exceptionHandler) { try { - return expressionCompile(expression).apply(instance, slice.call(arguments, 2, arguments.length)); + return expressionCompile(expression).call(instance); } catch (e) { (instance.$log || {error:error}).error(e); if (isFunction(exceptionHandler)) { @@ -161,12 +161,15 @@ function createScope(parent, services, existing) { $watch: function(watchExp, listener, exceptionHandler) { var watch = expressionCompile(watchExp), last; + listener = expressionCompile(listener); function watcher(){ var value = watch.call(instance), lastValue = last; if (last !== value) { last = value; - instance.$tryEval(listener, exceptionHandler, value, lastValue); + instance.$tryEval(function(){ + return listener.call(instance, value, lastValue); + }, exceptionHandler); } } instance.$onEval(PRIORITY_WATCH, watcher); diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 013b1bfc..6f5485e7 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -21,11 +21,11 @@ describe('scope/model', function(){ }); describe('$eval', function(){ - it('should eval function with correct this and pass arguments', function(){ + it('should eval function with correct this', function(){ var model = createScope(); - model.$eval(function(name){ - this.name = name; - }, 'works'); + model.$eval(function(){ + this.name = 'works'; + }); expect(model.name).toEqual('works'); }); |
