2 ms·
Here's another cool trick for making attributes of an object private: function MyObj() { var data = { id: 123, name: "Johnny Appl
by IgorPartola 13y ago
Here's another cool trick for making attributes of an object private:
function MyObj() {
var data = {
id: 123,
name: "Johnny Appleseed"
},
obj = {};
obj.printName = function() {
console.log(data.name);
};
obj.changeName = function(name) {
data.name = name;
};
return obj;
}
x = MyObj();
x.printName();
x.changeName("Igor");
x.printName();