zoukankan      html  css  js  c++  java
  • ECMAScript 引用类型

    Object对象

    新建对象

    var obj = new Object()
    var obj ={}
    var obj={age:23}
    ...
    View Code

     hasOwnProperty(property) 方法 

    var obj = {age:23}
    obj.hasOwnProperty("age") //返回true
    obj.hasOwnProperty("name") //返回false
    View Code
    var obj = {2:23}
    undefined
    obj.hasOwnProperty(2)  //返回true
    View Code

    isPrototypeOf(object) 判断该类型是否为另一个对象的原型

    var obj = new Object()
    
    Object.prototype.isPrototypeOf(obj)
    //true
    Array.prototype.isPrototypeOf(obj)
    //false
    View Code

    propertyIsEnumerable 判断给定的属性是否可以 for...in 语句进行枚举

    > var obj = {age:34,name:"abc"}
    undefined
    > obj.propertyIsEnumerable("name")
    true
    > obj.propertyIsEnumerable("age")
    true
    > obj.propertyIsEnumerable("constructor")
    false
    >
    View Code

    toString()  返回对象的原始字符串表示。

     var obj = {color:"yellow"} //'[object Object]'
    ValueOf() 返回最适合该对象的原始值
    >var obj = {color:"yellow"}
    undefined
    > obj.toString()
    '[object Object]'
    > obj.valueOf()
    { color: 'yellow' }
    >
    View Code

    Boolean

    没有什么可用性,不如使用原始值 true 、 false

    Number

    不常用,再见!

    String

    > var str = new String('hehehe')
    undefined
    > str.valueOf() == str.toString()
    true
    > str.length
    6
    > var result = str.concat(" bibi")
    undefined
    > result
    'hehehe bibi'
    > var str1=new String('aaaa')
    undefined
    > var str2=new String('hehehe')
    undefined
    > var str3=new String('zzz')
    undefined
    > str.localeCompare(str1)  // 1 代表 str大于str1
    1
    > str.localeCompare(str2)  // 相等
    0
    > str.localeCompare(str3) // 1 代表 str小于str1
    -1


    > str.toLocaleUpperCase() //upper 转大写
    'HEHEHE'
    > str.toLocaleLowerCase() //lower 转小写
    'hehehe'
    >

    对于负数参数,slice() 方法会用字符串的长度加上参数 (类似python切片),substring() 方法则将其作为 0 处理

    > str.slice(0,2)
    'he'
    > str.slice(0)
    'hehehe'
    > str.slice(-1)
    'e'
    > str.substring(0,6)
    'hehehe'
    > str.substring(-1)
    'hehehe'
    > str.substring(-1)
  • 相关阅读:
    C++的命名空间的使用
    QT编译和运行ROS功能包
    Ubuntu安装Chromium浏览器
    回文字符串(LCS变形)
    友好城市(LIS+结构体排序)
    免费馅饼
    C++ STL之set学习笔记
    Coloring Contention
    Charles in Charge
    最短路之Floyd,Dijkstra(朴素+队列优化)
  • 原文地址:https://www.cnblogs.com/bibi-feiniaoyuan/p/9361160.html
Copyright © 2011-2022 走看看