This article describes a quick and easy-to-understand JavaScript object-oriented quick-start example. Share it for your reference. The details are as follows:
Beginner of javascript object-oriented:
Copy the code as follows:<script language="javascript" type="text/javascript">
function Cat(){//The definition of objects in js is the same as that of functions, the difference is how to call them.
}
var cat1 = new Cat();//Create class instance
//The class attributes in js can be added dynamically and do not need to be written in the prototype object. JS object does not have the concept of class, but is called a prototype object
cat1.name = "puppy";
cat1.age = 4;
cat1.color="white";
document.write(cat1.name);
</script>
It is more commonly used to create objects directly using Object. For example, var cat1 = new prototype object name () -->var cat1 = new Cat(), there is no need to create a constructor first.
I hope this article will be helpful to everyone's JavaScript programming.