B
B
berman2011-08-21 08:44:21
JavaScript
berman, 2011-08-21 08:44:21

Way to track change of object instance properties in Javascript?

Hello Habrazhitel!
There is a constructor:

function Someobj(param1, param2) {
  this.param1 = param1;
  this.param2 = param2;
 }

In my case, the param1 and param2 parameters are object parameters that need to be updated like this:
var mySuperObj = new Someobj();
 mySuperObj.param1 = 20;
 mySuperObj.param2 = 10;

How can you track the change in these properties, except for checking in the interval and calling a similar function:
function updateParam1(obj, newVal) {
  obj.param1 = newVal;
 }

If what I asked is not possible, please suggest a more convenient way to update them.
Let me explain: in my case, the param1 and param2 properties are the x and y coordinates of the screen pseudo-object (pseudo-object on the canvas). And it's more common to update coordinates in the obj.x = val way than with functions.
Are there other ways?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
[
[email protected]><e, 2011-08-21
@berman

Getters and setters ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question