to make an entity with node js with this pattern
module.exports = class {
constructor(id) {
this.id = id;
}
}
then i require those class in my app.js, like this :
var Book = require('./entityClass');
var effectiveJava = new Book(1);
effectiveJava.title = 'Effective Java';
//checking title in book
console.log('book title : ' + effectiveJava.title);
surprisingly, those title field are works, and can show text in log.
i'm confuse, why those thing happen?
is it anyone can tell me about those thing
And what's wrong here? This is not Java, you can declare any field after you create object, even if they are undefined inside you class
What's the problem? If you DON'T want that to work, you can Object.freeze(this) at the bottom of the constructor
Обсуждают сегодня