原型,原型链

                           /*原型,原型链,call/apply(上)*/

    // 例题1:写一个方法,求一个字符串的字节长度[00:28 --> 09:03]
    /*
    定义和用法
       charCodeAt()方法可返回指定位置的字符 Unicode编码。这个返回值是0 - 65535之间的整数。
    */
    //语法
    //    stringObject.charCodeAt(index);
    // var str = "5545sdsad套法规";

    // function name(params) {
    //        var count = str.length;
    //        for (var i = 0; i < str.length; i++) {
    //            if(str.charCodeAt(i)){
    //                count ++;
    //            }              
    //        }

    //     var count = 0;
    //     for (var i = 0; i < str.length; i++) {
                
    //         if (str.charCodeAt(i) > 255) {
    //            count += 2;
    //             }else{
    //            count ++;
    //         }
                // return count;
    //     }
    // }


    //            原型
    //定义:原型是function对象的一个属性,他定义构造函数制造出的对象的公共祖先。
    //通过该构造函数产生的对象,可以继承该原型的属性和方法。原型也是对象 
    // Person.prototype --> 系统自带的属性,在函数刚诞生的时候,prototype就已经定义好了 [18:13 --> 25:22]
    // Person.prototype = {}  --> 相当于一个对象
    // Person.prototype.name = "lishuntao";
    // function Person(name, age, sex) {
    //     this.name = name;
    //     this.age = age;
    //     this.sex = sex;

    // }
    // var person = new Person(yangchen, 25, "男");
    // var person1 = new Person;


    //原型的特点:把对象公有的属性,提取到原型里面 [25:22 --> 29:45 --> 34:23 --> 36:50]
    // Car.prototype.name = "lishuntao";
    // Car.prototype.lang = 4900;
    // Car.prototype.carName = "兰博基尼";

    // function Car(color, owner) {
    //     this.color = color;
    //     this.owner = owner;
    // }
    // var car = new Car("yangchen", 4800,);
    // var car1 = new Car("chenke", 7800,); 
    //增,删,改,查


    


                   /*原型,原型链,call/apply(下)*/

    //原型的隐式属性  [02:45 --> 06:49]
    // Person.__proto__ --> 系统隐式的命名规则
    // function Person() {
    //     // var this = {       
    //     //    __proto__ : Percon.prototype,
    //     //    __proto__ 作用: 当你访问这个对象的属性的时候,这个对象如果没有这个属性的话,
                                //它就会通过__proto__指向的索引去找Person:prototype想要的属性,__prtot__相当于链接的关系,把原型和自己链接到一起
    //             //         };

    // }
    // var person = new Person();
    // Person.prototype.name = 'lishuntao';
    

    //例题1:[10:50 --> 14:50]
    // Person.prototype.name = "sunny";
    // function Person() {           
    // }
    // var person = new Person();
    // Person.prototype = {
    //     name : "cherry",
    // }
    

    //例题2:[17:30 --> 18:50]       
    // function Person() {   
    // }
    // Person.prototype.name = "sunny";
    // Person.prototype = {
    //     name : "cherry",
    // }
    // var person = new Person();

    
                        // 原型链
    //例题1:[23:03 --> 27:39 --> 32:51]
    // Groud.prototype.LastName = "qian";
    // function Groud() {};         
    // var groud = new Groud();

    // Father.prototype.LastName = groud;
    // function Father(params) {
    //     this.name = "xuming";
    // };
    // var father = new Father();

    // Son.prototype.LastName = father;
    // function Son() {
    //     this.hobbit = "smoke";
    // };
    // var son = new Son();

    
    //例题2:[35:00 --> 38:00]
    // Person.prototype = {
    //     name : 'a',
    //     sayName : function () {
    //         console.log(this.name);
    //     }
    // };

    // function Person() {
    //     this.name = 'b';
    // }

    // var person = new Person();


    //例题3:[38:00 --> 39:25]
    // Person.prototype = {
    //     height : 100,
    // }

    // function Person() {
    //     this.eat = function () {
    //         this.height ++;
    //     }
    // }
    // var person = new Person();


    //例题4:[40:00 --> 43:14]


    //Object.create() 
    // [43:00 --> 45:00]
    // var obj = Object.create(原型)
    // var obj = {name : 'sunny', age : 123};
    // var obj1 = Object.create(obj);


    //绝大多数对象的最终都会继承自Object.prototype,例外就是Objcet.create --> 构造的没有原型,连__proto__也没有
    //  [45:00 --> 49:11]


    // undefined.toString(),null.toString(); [50:29 --> 51:00]


    //toString [51:00 --> 55:45]


    //例题5:[55:45 --> 57:30]
    // Object.prototype.toString = function () {};
    // Person.prototype = {
    //     toString = function () {
    //         return "1111";
    //     }
    // };
    // function Person() {};
    // var person = new Person();


    //例题6:重写 [58:00 -- > 1:03:09]
    // Object.prototype.toString
    // Number.prototype.toString
    // Array.prototype.toString
    // Boolean.prototype.toString
    // String.prototype.toString

    // var obj = Object.create(null);
    // obj.toString = function () {
    //     return "嘤嘤嘤";
    // }
    // document.write(obj);


    //小BUG [1:03:39 --> 1:13:49]


                             /*call//apply*/
    //作用,改变this指向
    //区别,后面传的参数形式不同
    

    //例题1:[1:14:47 --> 1:21:50]
    // function Person(name, age) {
    //     this.name = name;
    //     this.age = age;
    // }

    // var person = new Person("li", 100);
    // var obj = {};
    // Person.call(obj);


    //例题2:[1:22:00 --> ]
    // function Person(name, age, sex) {
    //     this.name = name;
    //     this.age = age;
    //     this.sex = sex;
    // }

    // function Student(name, age, sex, tel, grade) {
    //     Person.call(this, name, age, sex)
    //     this.tel = tel;
    //     this.grade = grade;
    // }
    // var student = Student('li', 123, 'male', 139, 2017)


    //例题3:[1:37:00 --> 1:43:05]
    // function Wheel(wheelSize, style) {
    //     this.wheelSize = wheelSize;
    //     this.style = style;
    // }

    // function Sit(c, sitColor) {
    //     this.c = c;
    //     this.sitColor = sitColor;
    // }

    // function Model(height, width, len) {
    //     this.height = height;
    //     this.width = width;
    //     this.len = len;
    // }

    // function Car(wheelSize, style, c, sitColor, height, width, len) {
    //     Wheel.call(this, wheelSize, style);
    //     Sit.call(this, c, sitColor);
    //     Model.call(this, height, width, len);
    // }
    // var car = new Car(150, '花里胡哨', '真皮', 'red', 2000, 1200, 1800);


    //apply [1:43:00 --> 1:45:45]
    // call 需要把实参按照形参的个数传进去
    // apply 需要直接传 arguments


    // 例题4:JavaScript的call和apply方法是做什么的,有什么区别?
    /*
    答:call和apple的作用是改变this指向,传参列表不同
    */


    







    


            
        </script>        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值