This article describes the shared member properties and methods of object-oriented JavaScript and the usage of prototype keywords. Share it for your reference. The details are as follows:
Share member attributes and methods, use prototype keywords
function Dog(){}
=function(){
alert("hello,puppy");
}
="Yellow puppy";
var dog1 = new Dog();
var dog2 = new Dog();
();
();
="Xiaobai";
(+);
</script>
Pay attention to knowledge points:
(1) Use this. attribute name or method name, and they can also be shared with instantiated objects, but they are stored in a different space (stack area). In this case, each object has exclusive code. If there are many objects, it will make the efficiency less effective;
(2) Use prototype and store it in the same stack area, that is, multiple objects share code. When changing one of the objects, it does not affect the other objects.
I hope this article will be helpful to everyone's JavaScript programming.