对于scope 所拥有的属性
function Scope(){
this.$id ;
this.$$phase
this.$parent
this.$$watchers
this.$$nextSibling
this.$$prevSibling
this.$$childHead
this.$$childTail
this.$rrot
this.$$destroyed
this.$$listeners // 用于 $on ,$broadcast , $emit 的。
this.$$listenerCount
this.$$watchersCount
this.$$isolateBindings
}
拥有的方法
Scope.prototype = {
constructor:Scope,
// 新建 一个 子 scope
$new:function(isolate,parent){
}
// 创建一个 监听者 回调函数
$watch:function(watchExp,listener,objectEquality,prettyPrintExpression){
}
// 监听一个 数组 []
$watchGroup:function(watchExpressions,listener){
}
// 监听一个集合
$watchCollection:function(obj,listener){
}
// 脏检查
$digest:function(){
}
// 销毁
$destroy:function(){
}
// eval
// execute the expression on the current scope and return the result
$eval:function(expr,locals){
return $parse(expr)(this,locals);
}
// execute the expression on the current scope at a later point in time
$evalAsync:function(expr,locals){
}
//
$$postDigest:function(fn){
postDigestQueue.push(fn);
}
// $apply is used to execute an expression in angular form outside of the angular framework
// such as browser DOM events,setTimeout,XHR,third party libraries
$apply:function(expr){
}
//
$applyAsync:function(expr){
var scope = this;
expr && applyAsyncQueue.push($applyAsyncExpression);
scheduleApplyAsync();
function $applyAsyncExpression(){
scope.$eval(expr);
}
}
// 主要的借助于 scope.$$listeners = [] 实现的。
// 这里会 逐步的往父级查找,一级一级的往上查找
$on:function(name,listener){
}
// 同上
$emit:function(name,args){
}
// 同上
$broadcast:function(name,args){
}
}
对于创建子作用域
function createChildScopeClass(parent){
function ChildScope(){
this.$id ;
this.$$phase
this.$parent
this.$$watchers
...
}
// 这里是作为继承的写法。
ChildScope.prototype = parent;
return ChildScope;
}