当前位置: 移动技术网 > IT编程>开发语言>JavaScript > ECMAScript 引用类型

ECMAScript 引用类型

2018年07月25日  | 移动技术网IT编程  | 我要评论

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

Array

待补充~

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)

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网