js学习

1.构造函数学习

//1.构造函数的学习
            var Person=function(name,age){
                this.name=name;
                this.age=age;
                this.getName=function(){
                    alert("my name is "+this.name);
                    return this.name;
                }
            }
            //实例化两个Person对象
            var wu =new Person("wulihong",29);
            var liu=new Person("liuqiyun",28);
            //实例调用方法
            wu.getName();
            liu.getName();

2.闭包的学习

            2.A包定义变量a,方法AB
              B包定义变量a,方法AB
              为了解决变量名,方法名冲突问题,使用闭包解决
            function A(){
                var a=123;
                function AB(){
                    console.log("A包"+a);
                }
                return AB;//返回AB方法体
            }
            var resultA=A();//方法体
            resultA();//调用方法
            
            
            function B(){
                var a=456;
                function AB(){
                    console.log("B包"+a);
                }
                return AB;//返回AB方法体
            }
            var resultB=B();//方法体
            resultB();//调用方法
原文地址:https://www.cnblogs.com/liuqiyun/p/8893740.html