A preliminary understanding of the newly added getter/setter methods in ES5

In a simple sentence: Before ES5, when reading and writing the properties of an object, only its value was changed; after ES5, you can use getter and setter methods to perform developer-defined operations when reading and writing object properties .

To learn the in-depth responsive principle of vue today, you need to understand getters and setters. After some research, write your own understanding.

for example:

When using set, not only the assignment is realized, but the assigned value can also be printed out.

set setparam(param) {
	this.param = param;
	console.log('Not only can assign values, but also print!' + param);
}

The same is true for the get method, so there is no example. So what can this newly added feature do? The most classic is to achieve "two-way binding".

Here is the link to implement two-way binding for reference https://juejin.im/entry/58878370128fe1006c4a84ab

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324782469&siteId=291194637