In my limited experience about object type judgment,I don't know how to judge whether a value is Object Literal in JavaScript? I am searching for a long time on net.But no use.Please help or try to give some ideas how to achieve this.Thanks in advance!
The solution is: As we know,we can use 'typeof' or 'instanceof' to judge the type of value. For example,to judge an Array,we can use:
var array=[0,1,2,3,4];
if(Object.prototype.toString.call(array)==='[object Array]'){
alert('This is an Array!');
}
But now I want to check whether a value is Object Literal like this:
var obj={
a:2
};
How to judge it? My way is:
if(obj["__proto__"]["constructor"]===Object){
alert("This is Object Literal");
}
I am afraid this way is wrong.