初步了解面向对象

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>面向对象</title>
</head>
<body>
	
</body>
<script type="text/javascript">
  // var box="64554";
  // var str2=new String("55557");
             //Array
  // console.log(String.prototype)查找
  // 
  // 
  //自定义属性
   // String.prototype.leo=10;
   // console.log(box.leo)
   // 
   // 
   //定义一个方法
   // String.prototype.fly=function(){
   // 	alert("玮神")
   // }
   // box.fly()
   // 
   // 
   // 工厂函数,(普通函数)再调用的时候就是一个一个传参
    //function arr(){
     //console.log(this)//普通函数的this指向的是window
   // }
   // arr()
   // 
   // 
   // 
   // ES6 之前 是没有 Class 类关键字
   // 
   // 什么是面向对象,其实说白了就是构造函数
   // 
   // 
   // 
    //  function Leo(name,age){
    //  	this.name=name;
    //  	this.age=age;
    //  	this.fly=function(){
    //  		console.log(this.name+"今天"+this.age)
    //  		console.log(this)
    //  	}
    //  }
    //   Leo.prototype.fn = function(){
    //   	alert("这是fn方法")
     
    //   }

    // Leo.prototype.weight=function(){
    // 	return "我体重超标了"
    // }
    // 如果不用new就只是普通函数,
     // var fle=new Leo("小明",18);
     //      fle.fly()
         
     //      console.log(fle.weight())  
     //     
     //     
     //     
      // var json ={};

      //     json.name="小明";

      //     json.age = "18";

      //     json.fn=function(name){
      //     	this.length=54456;
      //     	console.log(this)
      //     	这里的this指向object
      //     }
      //     json.fn()

// String.prototype.fn=function(){
// 	return this.substring(0,1).toUpperCase()+this.substring(1);
// }
// console.log("sdfdsdsf".fn())
// 
// 
//   改变this指向
//   
    // function Leo1(name,age){
    // 	this.name = name;
    // 	this.age = age;
    // 	}

    // function Leo2(){
    	// Leo1.call(this,name,age)
    	//call()他传参的时候除去第一个是以普通参数的方法传参
    	//apply()除去第一个参数之外,之后的参数是以数组的方法去传参
        // this 指向的是Leo2
        // 改变Leo1的指向“call”,靠。
        // 吧Leo1的指向改变到Leo2里面 ,偷窃了1里面的所有属性
        // leo1.apply(this,[name,age])//继承那个就把所有参数写下来
    //     this.fn=function(){
    //     	alert("欢迎大家来学习面向对象")
    //     }
    // }
    //     Leo2.prototype=new Leo1("小红",25)
        // console.log(leo1)
        // var leo2 = new Leo2("夏明",18);
       // leo2.fn()
       // console.log(leo2.fn())
         // console.log(leo2)
         // 
         // 
         // 
         // 原型链
         var arr = new Array(5456,6,56,);
         var str = new String(444455)
         // console.log(arr.toString())
         // console.log(str.toString()) 
         // 
          var fn =function(){}
          // console.log(fn.toString())
          // console.log(Object.prototype)
        
          // var obj = new Object();
          // console.log(obj.substring(0,1))
          //  
            // console.log(String.prototype)
            // console.log(String.__proto__.__proto__) 
       
</script>
</html>    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值