Implementing “indexers” in JavaScript

Luke was wanting to know how to implement this C# code as JavaScript:
class Foo { public string Stuff { get; set; } public Foo() { } public Foo(string stuff) { this.Stuff = stuff; } public Foo this[string stuff] { get { return new Foo(stuff); } } publi…

Luke was wanting to know how to implement this C# code as JavaScript: class Foo { public string Stuff { get; set; } public Foo() { } public Foo(string stuff) { this.Stuff = stuff; } public Foo this[string stuff] { get { return new Foo(stuff); } } public Foo Bar() { Console.WriteLine("Darn tootin'"); return this; } } Class-implementation aside the interesting part that he was having trouble with was the indexer, basically being able to write this:
Print Share Comment Cite Upload Translate
CITATION GOES HERE CITATION GOES HERE
Select a language: