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…


This content originally appeared on Posts on LINQ to Fail and was authored by Posts on LINQ to Fail

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:


This content originally appeared on Posts on LINQ to Fail and was authored by Posts on LINQ to Fail


Print Share Comment Cite Upload Translate
APA
Posts on LINQ to Fail | Sciencx (2023-03-29T00:26:12+00:00) » Implementing “indexers” in JavaScript. Retrieved from https://www.scien.cx/2013/07/10/implementing-indexers-in-javascript/.
MLA
" » Implementing “indexers” in JavaScript." Posts on LINQ to Fail | Sciencx - Wednesday July 10, 2013, https://www.scien.cx/2013/07/10/implementing-indexers-in-javascript/
HARVARD
Posts on LINQ to Fail | Sciencx Wednesday July 10, 2013 » Implementing “indexers” in JavaScript., viewed 2023-03-29T00:26:12+00:00,<https://www.scien.cx/2013/07/10/implementing-indexers-in-javascript/>
VANCOUVER
Posts on LINQ to Fail | Sciencx - » Implementing “indexers” in JavaScript. [Internet]. [Accessed 2023-03-29T00:26:12+00:00]. Available from: https://www.scien.cx/2013/07/10/implementing-indexers-in-javascript/
CHICAGO
" » Implementing “indexers” in JavaScript." Posts on LINQ to Fail | Sciencx - Accessed 2023-03-29T00:26:12+00:00. https://www.scien.cx/2013/07/10/implementing-indexers-in-javascript/
IEEE
" » Implementing “indexers” in JavaScript." Posts on LINQ to Fail | Sciencx [Online]. Available: https://www.scien.cx/2013/07/10/implementing-indexers-in-javascript/. [Accessed: 2023-03-29T00:26:12+00:00]
rf:citation
» Implementing “indexers” in JavaScript | Posts on LINQ to Fail | Sciencx | https://www.scien.cx/2013/07/10/implementing-indexers-in-javascript/ | 2023-03-29T00:26:12+00:00
https://github.com/addpipe/simple-recorderjs-demo