Home >Web Front-end >JS Tutorial >Some views on JavaScript object prototype_js object-oriented

Some views on JavaScript object prototype_js object-oriented

WBOY
WBOYOriginal
2016-05-16 18:19:26991browse

1. function func() {
this.name = "huhao";//This variable is private and can only be accessed when creating a new object, such as var obj= new func(); obj. The name is accessible and can be modified, but it can only be modified in the new object,
}
func.age="11"; //This variable cannot be inherited, only func. age to access
func.prototype.address="Anhui Province";//This variable cannot be accessed directly by func.address, but can only be accessed by var obj= new func(); obj.address, and at the same time in obj. address can be modified



Conclusion:
1. The name and address objects are private and invisible. However, newly constructed objects are developed.

2.age attribute is private, visible and cannot be inherited.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn