Below code is creating a dictionary(foo) and then adding a method(bar) and property by name ack in that dictionary.
var foo = {};
foo.bar = function(){
this.ack=3;
};
foo.bar();
In python, if i try doing the same,
>>> foo = {}
>>> def f():
this.ack=3
>>> foo.bar = f
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
foo.bar = f
AttributeError: 'dict' object has no attribute 'bar'
My question:
Instead of (key, value) pairs, How can JavaScript allow a method(
bar) become a member of dictionary?In addition, How can JavaScript allow name
ackwith value 3(this is not key-value) become a member of dictionary?