zoukankan      html  css  js  c++  java
  • JavaScript的自定义对象

    javasrcipt中的对象 Object
    javascript中{}可以代表对象
    1 javascript已经存在的类型的对象
    var v = new Date();
    var obj1 = new Object(), obj2 = {};//Object 对象
    var arr1 = new Array(), arr2 = [];//Array 对象
    var boo1 = new Boolean(true), boo2 = true;//Boolean 对象
    var num1 = new Number(123), num2 = 123.45;//Number 对象
    var str1 = new String("abc"), str2 = 'abc';//String 对象
    2 自定义的对象1:
    JSON
    var person={firstname:"John", lastname:"Doe", id:5566};
    alert(person.firstname);
    alert(person.lastname);
    alert(person.id);


    3 自定义的对象2:
    var p = 
    {       
      grade:1,
      name : "tom",
      age:27,
      sex:"男",
     
      speak:function(words)
      {
     alert(this.name+"说:"+words+"!");
      }

    }
    p.speak("hello");
    4 自定义的对象3:
    function Person(name){
    this.name = name;
    this.age = 20;

    this.say=say;
    }

    function say(){
    document.write(this.name+":大家好,我今年"+this.age+"岁了");
    }
    var p = new Person("张三");
    p.say();

    -----------------------------
    function Person(name){
    this.id = 1;
    this.name = name;
    this.age = 20;

    this.say=function(msg){
    document.write(this.name+" 说:"+msg);
    };
    }
    var p = new Person("张三");
    p.say();

  • 相关阅读:
    函数 对象 入门总结
    js 禁止复制粘贴全选
    CSS3个人盲点总结【总结中..........】
    was设置事务超时
    阿里前DBA的故事
    转型思考
    自卑
    关于BigDecimal的使用
    少睡与吸烟影响IQ
    DB2中OLAP函数使用示例
  • 原文地址:https://www.cnblogs.com/jalenFish/p/14099087.html
Copyright © 2011-2022 走看看