Hi Gordon
I just found learned the functionality of get and set.
http://jsconsole.com/?var%20person%20%3D%20%7B%0A%20%20_name%3A%20%27Marion%27%2C%0A%20%20get%20name()%20%7B%0A%20%20%20console.log(%27read%5Cn%27)%3B%0A%20%20%20return%20this._name%3B%0A%20%20%7D%2C%0A%20%20set%20name(value)%20%7B%0A%20%20%20%20console.log(%27write%5Cn%27)%3B%0A%20%20%20%20this._name%3Dvalue%3B%0A%20%20%7D%0A%7D%3B%0A%0Aperson.name%3D%27Michelle%27%3B
Code:
var person = { _name: 'Marion', get name() { console.log('read\n'); return this._name; }, set name(value) {
console.log('write\n'); this._name=value;
} };
person.name='Michelle';
I just got a syntax error. Any chance that this will work on espruino too ?
Thanks
Sacha
@Sacha started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi Gordon
I just found learned the functionality of get and set.
http://jsconsole.com/?var%20person%20%3D%20%7B%0A%20%20_name%3A%20%27Marion%27%2C%0A%20%20get%20name()%20%7B%0A%20%20%20console.log(%27read%5Cn%27)%3B%0A%20%20%20return%20this._name%3B%0A%20%20%7D%2C%0A%20%20set%20name(value)%20%7B%0A%20%20%20%20console.log(%27write%5Cn%27)%3B%0A%20%20%20%20this._name%3Dvalue%3B%0A%20%20%7D%0A%7D%3B%0A%0Aperson.name%3D%27Michelle%27%3B
Code:
var person = {
_name: 'Marion',
get name() {
console.log('read\n');
return this._name;
},
set name(value) {
}
};
person.name='Michelle';
I just got a syntax error. Any chance that this will work on espruino too ?
Thanks
Sacha