当前位置:网站首页>JS implementation private attribute

JS implementation private attribute

2022-04-23 17:41:00 KK should continue to work hard

JS Implement private properties

  1. Based on closure
function P(name){
    
	var _name = name;
	this.getName=function(){
    
		return _name;
	} 
}
var p = new P("xxx");
console.log(p._name); //undefined
console.log(p.getName());   //xxx

版权声明
本文为[KK should continue to work hard]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230551363620.html