zoukankan      html  css  js  c++  java
  • JS对象的几个方法介绍

    1.hasOwnProperty 判断是不是对象自身的属性,如果是继承的返回false否则true

    function Fn(){
    }
    Fn.prototype.num = 10;
    var obj = new Fn(); obj.id = 1;
    console.log(obj.hasOwnProperty(
    "id")); //true console.log(obj.hasOwnProperty("num")); //false

    2.constructor 返回对象的构造函数

    var obj = new Function();
    console.log(obj.constructor); //function Function() { [native code] }

    3.instanceof 判断对象是否在某个构造函数上

    var fn = new Function();
    console.log(fn instanceof Function); //true
    console.log(fn instanceof Object); //true
    console.log(fn instanceof String); //false

    4.toString 把对象转换成字符串

    var arr = [1,2,3];
    console.log(arr.toString()); //1,2,3
  • 相关阅读:
    方法
    Go中的OOP
    GO 结构体
    指针
    闭包
    回调函数
    匿名函数
    函数的数据类型及本质
    defer语句
    递归函数
  • 原文地址:https://www.cnblogs.com/pssp/p/5229395.html
Copyright © 2011-2022 走看看