ECMAScript reference type

Object object

New object

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

hasOwnProperty(property) method

var obj = {age:23}
obj.hasOwnProperty("age") //Return true
obj.hasOwnProperty("name") //Return false
var obj = {2:23}
undefined
obj.hasOwnProperty(2)  //Return true

isPrototypeOf(object) determines whether the type is the prototype of another object

var obj = new Object()

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

propertyIsEnumerable determines whether a given property can be enumerated by the for...in statement

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

toString() returns the original string representation of the object.

 var obj = {color:"yellow"} //'[object Object]'
ValueOf() returns the original value that best suits the object
>var obj = {color:"yellow"}
undefined
> obj.toString()
'[object Object]'
> obj.valueOf()
{ color: 'yellow' }
>

Boolean

There is no availability. It is better to use the original values of true and false

Number

Not often. Goodbye!

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 means str is greater than str1
1
> str.localeCompare(str2)  // Equal
0
> str.localeCompare(str3) // 1 representative str less than str1
-1


> str.toLocaleUpperCase() //Upper to upper case
'HEHEHE'
> str.toLocaleLowerCase() //lower to lowercase
'hehehe'
>

For negative parameters, slice() method will add the length of string (similar to python slice), and substring() method will treat it as 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)

Tags: Javascript less Python

Posted on Fri, 31 Jan 2020 09:48:36 -0800 by dc2000