• js精要之构造函数


    // 枚举对象

      var obj = {}
        obj.name = "bob";
        obj.age = "22";
        obj.sex = "boy";
        console.log(obj);
        for(var sum in obj){
           // console.log(sum);
        }

    // 构造函数 sayName自有方法

       function Person(name){
            this.name = name;
            this.sayName = function(){
                console.log(this.name);
            }
        }
        var person1 = new Person("aaa");
        var person2 = new Person("bbb");
        console.log(person1.name); // aaa
        console.log(person2.name); // bbb
        person1.sayName(); // aaa
        person2.sayName(); // bbb

    // 每个函数都带有一个prototype属性  sayName1 为原型方法

      function Person1(name){
            this.name = name;
        }
        Person1.prototype.sayName1 = function(){
            console.log(this.name);
        }
        var person1a = new Person1("aaa-v");
        var person2a = new Person1("bbb-v");
        console.log(person1a.name); // aaa-v
        console.log(person2a.name); // bbb-v
        person1a.sayName1(); // aaa-v
        person2a.sayName1(); // bbb-v

    // 鉴别一个原型属性

       function hasPrototypeProperty(name,object){
            return name in object && !object.hasOwnProperty(name);
        }
        var book = {
            title:"this is book!"
        }
        console.log(hasPrototypeProperty("title",book)); //false
        console.log(hasPrototypeProperty("hasOwnProperty",book)); //true
  • 相关阅读:
    python 解释器交互模块 -- sys
    python 操作系统模块 -- OS
    python 随机数模块 -- random
    python 时间模块 -- time
    Python 面向对象
    python 模块
    python -- 面向对象进阶
    github连接提示
    linux day4
    git基本使用
  • 原文地址:https://www.cnblogs.com/pangzi666/p/5190597.html
Copyright © 2020-2023  润新知