zoukankan      html  css  js  c++  java
  • 面像对象略整理

    function Person(name, age, job){
    this.name = name;
    this.age = age;
    this.job = job;
    this.sayName = function(name){
    alert(this.name);
    };
    }
    var person1 = new Person("Nicholas", 29, "Software Engineer");
    var person2 = new Person("Greg", 27, "Doctor");
    console.log(person1.sayName==person2.sayName)//fasle
    console.log(person1.sayName()==person2.sayName())//true

    function Perple(){};
    Perple.prototype.name="hong";
    Perple.prototype.age=18;
    Perple.prototype.height="188cm"
    Perple.prototype.sayName=function(){
    alert(this.name)
    };
    var p3=new Perple();
    var p4=new Perple();
    alert(p3.sayName==p4.sayName);//true
    console.log(Perple.prototype.isPrototypeOf(p3));//true;isPrototypeOf()检测一个原型上是不是有这个实例
    console.log(p3.hasOwnProperty("name"))//fasle检测一个属性是不是存在实例中
    p4.name="圆圆";
    alert(hasPrototypeProperty(p3, "name"))
    console.log(p4.hasOwnProperty("name"));//true
    console.log("name" in p4)//true检测该属性是否存在实例 || 原型中(二选一符合就返回true)

    var obj={name:"hong",age:"45"};
    for(var oo in obj){//for in 的用法
    console.log("属性值:"+obj[oo]+" 属性名:"+oo);
    }

  • 相关阅读:
    vmware12中安装MAC OS X 10.10
    AOL search
    [python]错误检测及异常处理try-except
    [推荐]
    [python]打开文件操作open用法
    MAC使用小技巧
    [推荐]
    [python]python中的if, while, for
    [python]python字典
    [python]python列表、元组
  • 原文地址:https://www.cnblogs.com/into/p/4561645.html
Copyright © 2011-2022 走看看