Add a variable to a class instance at runtime: Difference between revisions
Add a variable to a class instance at runtime (view source)
Revision as of 17:40, 2 June 2010
, 14 years ago→{{header|J}}
(autohotkey example) |
|||
Line 213:
=={{header|J}}==
If you assign a value to the name which references a property of a class instance, that name within that instance gets that value.
<lang j> C=:<'exampleclass' NB. this will be our class name
V__C=: 0 NB. ensure the class exists
OBJ2=:conew 'exampleclass' NB. create another instance
V__OBJ1,V__OBJ2 NB. both of our instances exist
0
W__OBJ1 NB. instance does not have a W
|value error
W__OBJ1=: 0 NB. here, we add a W to this instance
W__OBJ1 NB. this instance now has a W
0
W__OBJ2 NB. our other instance does not
|value error</lang>
=={{header|JavaScript}}==
|