User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

js:oop-pr [2017-11-25 17:28] (current)
Line 1: Line 1:
 +=====Pseudo private attributes in JS=====
 +
 +Very pseudo. =)
 +
 +<code javascript oop.js> ​
 +#​!/​usr/​bin/​env node
 +
 +'use strict';​
 +
 +class A {
 +    constructor(name) {
 +        this._name = name;
 +    }
 +
 +    name(n) {
 +        if (n) { this._name = n; return this; }
 +        return this._name;
 +    }
 +}
 +
 +let a = new A("​abc"​);​
 +
 +console.log("​name = " + a.name());
 +a.name("​bbc"​);​
 +console.log("​name = " + a.name());
 +
 +//EOF
 +</​code>​