Home > Backend Development > PHP Tutorial > Why can't JS private variables be accessed?

Why can't JS private variables be accessed?

WBOY
Release: 2016-08-23 09:02:18
Original
806 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