Смотрите мой новый код стайл ^___^ круто? Какие недостатки?
ui.service('$scope', ['$parse', function($parse) {
return {
$$watchers: [],
$new: function() {
var scope = Object.create(this);
return scope;
},
$watch: function(watch, handler, byValue) {
if (isString(watch)) {
watch = $parse(watch);
}
var watchers = this.$$watchers;
var watcher = {
scope : this,
watch : watch,
handler : handler,
byValue : byValue,
lastValue: undefined
};
watchers.push(watcher);
return function() {
var index = watchers.indexOf(watcher);
watchers.splice(index, 1);
};
},
$digest: function() {
var watchers = this.$$watchers;
watchers.forEach(function(watcher) {
var scope = watcher.scope;
var watch = watcher.watch;
var handler = watcher.handler;
var byValue = watcher.byValue; //TODO:
var lastValue = watcher.lastValue;
var value = watch(scope);
if (value !== lastValue) {
handler(value, lastValue);
watcher.lastValue = value;
}
});
},
$eval: function(func) {
if (isString(func)) {
func = $parse(func);
}
func(this);
},
$apply: function() {
this.$eval(func);
this.$digest();
}
};
}]);