zoukankan      html  css  js  c++  java
  • javascript面向对象技术基础总结

    javascript面向对象和php不太一样,语法不太相同,总结如下

    //cat 对象
    function Cat(name,color){
        this.name = name;//不确定的成员属性
        this.color = color;//不确定的成员属性
    }
    Cat.prototype.type = '猫科动物';//固定的成员属性
    Cat.prototype.eat = function(){//成员方法
        alert('吃老鼠');    
    }
    
    //实例化对象
    var cat1 = new Cat('大毛','黄色');
    
    //访问成员属性和方法
    //alert(cat1.name);     //大毛
    //alert(cat1.color);    //黄色
    //alert(cat1.type);     //猫科动物
    //cat1.eat();           //alert 吃老鼠
    
    //判断实例与对象的关系
    //alert(cat1 instanceof Cat);               //true  cat1是否是Cat的实例
    //alert(Cat.prototype.isPrototypeOf(cat1)); //true  cat1是否是Cat的实例
    
    //判断属性与实例的关系
    //alert(cat1.hasOwnProperty("name"));       //true  判断属性是否是自己的熟悉还是继承自prototype的属性
    //alert(cat1.hasOwnProperty("type"));       //false 判断属性是否是自己的熟悉还是继承自prototype的属性
    //alert("name" in cat1);                    //true  判断属性是否属于实例
    //alert('type' in cat1);                    //true  判断属性是否属于实例
    
    //in 遍历对象中的所有属性
    for(var prop in cat1){
        alert("cat1["+prop+"]");    
    }
    If the copyright belongs to the longfei, please indicate the source!!!
  • 相关阅读:
    通知advice
    通知advice
    springmvc+mybatis需要的jar包与详解
    sass参考手册
    Mapper
    排序
    常见设计模式
    JavaScript之事件循环,宏任务与微任务
    字符串翻转
    eeeeeeeeeeeeeeeeeeeeee
  • 原文地址:https://www.cnblogs.com/longfeiPHP/p/5977292.html
Copyright © 2011-2022 走看看