zoukankan      html  css  js  c++  java
  • javascript对象

    一.类型

    五种基本类型:

      nullundefinednumberbooleanstring

      null表示没有声明,undefined表示声明后没有初始化,其余三个有对应的包装对象NumberBooleanString

    对象类型:

      object,比如常用的ArrayDateRegExp等,我们最常用的Function也是个对象

    二.类型识别函数

      验证类型  typeof 对象名;  输出对象类型

    三.javascript对象

      1.声明对象

      //用对象的方法声明对象

        var newobj = new Object();
        newobj.name = "jim";
        newobj.method = function(){
          console.warn(this.name);
        }
      //用字面值方法构造对象
        var obj = {
          name:"oliver",
          method:function(){
            console.warn(this.name);
          }
        }
      //使用方法来创建多个变量
        function createObj(name){
          var obj = {
            name:name,
            method:function(){
              console.warn("demo");
            }
          }
          return obj;
        }
      //定义构造方法
        function Person(name,age){
          this.name = name;
          this.age = age;
            this.method = function(){
            console.warn(this.constructor);//指向该对象的构造器function Person(name,age){}
            console.warn("new person");
            }
          //任何函数使用new运算符就是构造函数
        }

      2.对象间关系

      function Monkey(gender){

        this.gender = gender;
        this.method = function(){
          console.warn(this.gender);  
        }
      }

      
    function Person(name,age){
        this.name = name;
        this.age = age;
        this.prototype = new Monkey("male");//用另外一个构造函数赋值原型
        this.method = function(){
          console.warn(this.prototype);
        }
      }

      $(function(){
        $(".proto").click(function(){
          var p = new Person("jim",20);
          p.method();
        });
      });

  • 相关阅读:
    位图 与矢量图对比
    用ocam工具录视频及转换视频 ffmpeg
    教学设计-饭后百步走
    教学设计例--跟小猴子一起玩
    教学设计-妈妈跳舞
    教学设计--Scratch2.0入门介绍
    Scratch2.0在线注册用户并使用帮助
    下载Scratch2.0离线版并安装教程
    把Sratch作品转为swf文件
    跟小猴子开心玩
  • 原文地址:https://www.cnblogs.com/brolanda/p/4503753.html
Copyright © 2011-2022 走看看