Pergunta

I may sound weird for this, please forgive me if this is an off topic question, but Since I came from java background and now working on nodejs last 1 week, at many places I personally felt that I should use something like Bean architecture with setters and getters feature (as we do have in java term).

Is there any way through which I can achieve this in nodejs/javascript ?,

suppose I have json data in my hand retrieved from db call, how can I convert it into a class with respective properties ?

(I have intermediate knowledge about javascript and prototype.)
Any help would be appreciated... thanks.

Foi útil?

Solução

JSON that you get is already an object =) Any way you can create a constructor function and pass this json as parameter. And do whatever you like

Outras dicas

In addition of topic Getter/Setter look at

 __defineGetter__
 __defineSetter__

they are default basic object methods, to specify getters and setters in JS (not sure abount NODE)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top