function abs(name, values) { obj = {} obj[name] = values return obj } abs('good', 100) abs('bad', 10) abs('normal', 50) alert(obj.good) alert(obj.bad) alert(obj.normal) 

The property is replaced each time it is called, and the object must have 3 different properties.

  • one
    @zloctb. To format a code, select it with the mouse and click on the button 101010 of the editor. - Nicolas Chabanovsky

2 answers 2

 (function(){ var obj = {}; window.abs = function(name, values) { obj[ name ] = values; return obj; } }()); abs('good',100); abs('bad',10); abs('normal',50); 
  • Please, how does the code work get it? - Zowie
  • Not really! Is a global variable created through which we get access to a private property (var obj)? - zloctb
  • His Majesty Closing - Specter
 var obj = {}; function abs(name, value) { obj[name] = value; return obj; } abs('good', 100); abs('bad', 10); abs('normal', 50); alert(obj.good); alert(obj.bad); alert(obj.normal);