Why can't JS private variables be accessed?

WBOY
Release: 2016-08-23 09:02:18
Original
749 people have browsed it
<code>function Customer(name) {  
    var risk = 0;  
    this.name = name;  
}  
var customer = new Customer("aa"); 
console.log(customer.name);  // aa
console.log(customer.risk); // undefined  </code>
Copy after login

Excuse me, why is customer.risk inaccessible but customer.name is accessible? Whose private variable is risk? Is it customer's? If so, why can't customer access his own private variable?

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!