• 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();

  • 相关阅读:
    词法分析程序
    关于编译原理
    超神c语言文法
    linux基本命令
    用bat来注册ocx
    当web配置文件 appSettings配置的东西越来越多时,可以拆开了。
    MVC的URL路由规则
    ASP.NET MVC 中如何实现基于角色的权限控制
    查cc攻击
    关于session介绍
  • 原文地址:https://www.cnblogs.com/jalenFish/p/14099087.html
Copyright © 2020-2023  润新知