标签:资源 操作方法 决定 person ref 需要 targe lse blank
链式调用原理就是作用域链;实现需要做的工作;
对象方法的处理 (操作方法)
处理完成返回对象的引用(操作对象)
第2步链式实现的方式:
一:
var person = {
    set: function (age){
        this.age = 10;  //this调用位置决定其词法作用域
        return person ;
    },
    get: function (){
        var age = this.age;
        if(age < 6){
            return ‘我还是个宝宝‘;
        }else if(age < 18){
            return ‘我还是个少年‘;
        }else{
         //……
        }
    }
}
资源搜索网站大全 https://www.renrenfan.com.cn 广州VI设计公司https://www.houdianzi.com
二:
var Person = function() {};
Person.prototype.set = function (age){
    this.age = 10; 
    return this; //this调用位置决定其词法作用域
}
Person.prototype.get = function (){
    var age = this.age;
    if(age < 6){
        return ‘我还是个宝宝‘;
    }else if(age < 18){
        return ‘我还是个少年‘;
    }else{
     //……
    }
}
var person = new Person();
person.set(10).get(); // ‘我还是个少年‘标签:资源 操作方法 决定 person ref 需要 targe lse blank
原文地址:https://www.cnblogs.com/xiaonian8/p/14124270.html