mardi 3 février 2015

create private properties in oloo style


I am new to javascript and its a bit confusing for me: There is so called oloo style in javascript. Which we do not simulate "class" inheritance, but using delegation. Its nice and more truly javascript style as for me. But it's a bit confusing to me how can we make "private" properties with this style? with function we would make closures. For example I would like to create some objects and add "private" properties to them, but I also want to create getters a setters for changing that properties. How could I do that? Maybe using in some way defineProperty method? pseudo code example:



parent object Vehicle.
car1 = Object.create(Vehicle).InitializeMethod(color, type)
car2 = Object.create(Vehicle).InitializeMethod(color, type)

car1.setColer("some")
car1.getColor() => "some"
car1.color => undefined or error(in strict mode)car1.color = "some" => error


thanks in advice.





Aucun commentaire:

Enregistrer un commentaire