javascript深入原型

/*继承*/
function ClassA(obj){
   this.color = obj;
   this.b = "TK";
   this.sayColor = function(){
      console.log(this.color);
   }
   this.x = function(){
      console.log("全部调用了?"+this.b);
   }
}

/*继承ClassA的方法1 是将其作为常规函数,然后调用者的引用指向该常规函数*/
function ClassB(obj){
   this.newMethod = ClassA;
   //函数调用
   this.newMethod(obj);
   delete this.newMethod;

   /*es中引入了call()方法  对继承进行了封装*/
   //ClassA.call(this,obj);
   
   this.name = obj;
   this.sayName = function(){
      console.log(this.name);
   }
}


/*原型链*/
function ClassF(){
   
}
ClassF.prototype.attrOne = 'protest';
ClassF.prototype.attrMethod = function(){
   console.log(this.attrOne);
}

function ClassS(){
   
}

ClassS.prototype = new ClassF();

ClassS.prototype.myAttr = '';
ClassS.prototype.myMethod = function(){
   console.log(this.myAttr);
}

/*混合模式联系 -- 对象冒充继承构造函数属性  原型继承构造函数方法*/
function fTree(obj){
   this.name = obj;
   this.fMethod = function(){
      console.log(this.name);
   }
}

function subTree(ownAttr,obj){
   
   /*对象冒充继承父类属性*/
   fTree.call(this,obj);
   this.ownAttr = ownAttr;
}

/*使用原型继承父类方法*/
subTree.prototype = new fTree();
subTree.prototype.ownMethod = function(){
   console.log(this.ownAttr);
}

/*回调函数理解*/
function outerFunc(obj,callbackFunc1,callbackFunc2){
   console.log(111111111111);
   callbackFunc1();
   callbackFunc2("函数调用2.。。。。。。。。。。。。");
}


function createServer(callbackFunc){
   console.log("开始创建服务器.....");
   function req(){
      console.log("请求信息............");
   }
   function res(){
      console.log("响应信息............");
   }
   callbackFunc(req,res);
}

function loopClose(obj,param1,callFunc){
   callFunc(obj);
}


/*闭包再次理解*/
function generateClosure(){
   var count = 0;
   var get = function(){
      count++;
      return count;
   }
   return get;
}

/*递归调用*/
function recursiveFunc(num) {
   if(num <= 1) {
      return 1;
   } else {
      //console.log(arguments);
      return num * arguments.callee(num-1);  
   }
}

console.log(recursiveFunc.toString());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值