angular 之 $rootScope

对于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;
}




转载于:https://my.oschina.net/bosscheng/blog/550579

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值