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 Updates
APA

Posts on LINQ to Fail | Sciencx (2013-07-10T00:00:00+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 ,<https://www.scien.cx/2013/07/10/implementing-indexers-in-javascript/>
VANCOUVER
Posts on LINQ to Fail | Sciencx - » Implementing “indexers” in JavaScript. [Internet]. [Accessed ]. 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 . 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: ]
rf:citation
» Implementing “indexers” in JavaScript | Posts on LINQ to Fail | Sciencx | https://www.scien.cx/2013/07/10/implementing-indexers-in-javascript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.