Jump to content

Add a variable to a class instance at runtime: Difference between revisions

CoffeeScript
m (→‎{{header|Icon}} and {{header|Unicon}}: mention some caveats and note we didn't quite pass go (but would still like my $200))
(CoffeeScript)
Line 70:
<lang AutoHotkey>e := {}
e.foo := 1 </lang>
 
=={{header|CoffeeScript}}==
<lang coffeescript># CoffeeScript is dynamic, just like the Javascript it compiles to.
# You can dynamically add attributes to objects.
 
# First create an object very simply.
e = {}
e.foo = "bar"
e.yo = -> "baz"
console.log e.foo, e.yo()
 
# CS also has class syntax to instantiate objects, the details of which
# aren't shown here. The mechanism to add members is the same, though.
class Empty
# empty class
e = new Empty()
e.foo = "bar"
e.yo = -> "baz"
console.log e.foo, e.yo()
</lang>
 
=={{header|Common Lisp}}==
Line 123 ⟶ 144:
CL-USER 62 > (slot-value *an-instance* 'slot1)
23</pre>
 
 
 
=={{header|D}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.