0
lain posted
how to set private property in JavaScript ?
how to set private property in JavaScript ?trying to make private property name in Product
var Product = (function() {
var name;
function Product(name) {
this.name = name;
}
Product.prototype.getName = function() {
return this.name;
};
return Product;
}());
var product = Product ('Apple');
console.log(product.getName());//Apple
delete product.name;//true
console.log(product.getName());//undefined
i able to delete product.name . it means its not private key so how to set private property in JavaScript ?