zoukankan      html  css  js  c++  java
  • javascript对象的标签

    [[proto]]标签


    [[class]]标签


    [[class]] 标签,代表这对象是哪个类型的。在js中不能直接访问到。可以通过Object.prototype.toString.call(obj)间接获取对象的类型

    Object.prototype.toString.call(1).slice(8,-1);   //"Number"
    
    Object.prototype.toString.call("1").slice(8,-1);  //"String"
    
    Object.prototype.toString.call(new Object()).slice(8,-1);  //Object
    
    Object.prototype.toString.call(new Array).slice(8,-1);  //Array
    
    Object.prototype.toString.call(null).slice(8,-1);  //null
    
    Object.prototype.toString.call(undefined).slice(8,-1);  //"Undefined"
    
    Object.prototype.toString.call(true).slice(8,-1); //"Boolean"

    [[extensible]]标签


    [[extensible]] 标签对象上的属性,是否可以被继续添加

    var obj = {x:1,y:2}
    
    Object.isExtensible(obj)  //true  是否可以扩展
    
    Object.preventExtensions(obj)  //阻止扩展
    
    obj.z = 90   
    
    obj   //Object {x: 1, y: 2}
    
    obj.z   //undefined
    
    Object.seal(obj);  //将对象上所有的属性 变成 不可配置
    
    Object.getOwnPropertyDescriptor(obj,'y')  //Object {value: 2, writable: true, enumerable: true, configurable: false}
    
    Object.getOwnPropertyDescriptor(obj,'x')  //Object {value: 1, writable: true, enumerable: true, configurable: false}
    
    Object.isSealed(obj);  //true
    
    
    var o = {x:1,y:2};
    
    Object.freeze(o);  、//将对象上所有属性 变为不可写,不可配置
    
    Object.isFrozen(o)   //true
    
    Object.getOwnPropertyDescriptor(o,'x')   //Object {value: 1, writable: false, enumerable: true, configurable: false}
    
    Object.getOwnPropertyDescriptor(o,'y')   //Object {value: 2, writable: false, enumerable: true, configurable: false}
  • 相关阅读:
    P1371 NOI元丹
    最小费用最大流
    City Game UVALive
    P2389 电脑班的裁员
    P1959 遗址_NOI导刊2009普及(6)
    P2700 逐个击破
    P1630 求和
    P4310 绝世好题
    java常用类:1。包装类(以Integer类为例)2.String类 3.StringBuffer
    java异常,异常处理,异常类 关键字:throws 和 throw 自定义的异常类
  • 原文地址:https://www.cnblogs.com/dsitn/p/7074338.html
Copyright © 2011-2022 走看看