This article further analyzes and describes the in-depth understanding of object-oriented objects in JavaScript. Share it for your reference. The specific analysis is as follows:
In javascript object-oriented programming, it can be understood that everything is an object. The example code is as follows:
Copy the code as follows:<script language="javascript" type="text/javascript">
function Cat(){
}
var cat1 = new Cat();//Create class instance
cat1.name = "puppy";
cat1.age = 4;
cat1.color="white";
document.write(cat1.name);
document.writeln(cat1.constructor);//The object after instantiation is an object
document.writeln(typeof(cat1)+"<hr />");
document.writeln(Cat.constructor);//The prototype object itself is also an object
document.writeln(typeof Cat+"<hr />");
var b="hello";//Stands are also objects
document.writeln(b.constructor);//Output its constructor
document.writeln(typeof b+"<hr />");
var c=123;//The value is also an object
document.writeln(c.constructor);
document.writeln(typeof c+"<hr />");
</script>
Determine whether an instantiated object is a certain prototype object type
The code copy is as follows: if(cat1 instanceof Cat){//The same method as php
window.alert("ok");
}
I hope this article will be helpful to everyone's JavaScript programming.