How JavaScript uses closures to implement private variables
This article mainly introduces JavaScript how to use closures to achieve private variables, the article is very detailed, has a certain reference value, interested friends must read it!
Using closures to implement private variables function Person (name, age) {this.getName = function () {return name;}; this.setName = function (newName) {name = newName;}; this.getAge = function () {return age;}; this.setAge = function (newAge) {age = newAge;}; / / property var occupation; this.getOccupation = function () {return occupation;} not initialized in the constructor This.setOccupation = function (newOcc) {occupation = newOcc;};} this is all about the article "how JavaScript uses closures to implement private variables". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!