build-your-own-angularjs
build-your-own-angularjs copied to clipboard
Question in Integrating Expressions to Scopes
In page 349, in the case 'accepts expressions for watch functions':
it('accepts expressions for watch functions', function() {
var theValue;
scope.aValue = 42;
scope.$watch('aValue', function(newValue, oldValue, scope) {
theValue = newValue;
});
scope.$digest();
expect(theValue).toBe(42);
});
scope.js
Scope.prototype.$watch = function(watchFn, listenerFn, valueEq) {
var self = this;
var watcher = {
watchFn: parse(watchFn),
listenerFn: listenerFn || function() { },
last: initWatchVal,
valueEq: !!valueEq
};
...
}
I am confused about that how watchFn : parse(watchFn)
relation to the Scope. When parse(watchFn)
return the function functon() {return aValue}
, witch the variable aValue
is not relation to the scope