Tag: Objects

  • Namespace, Encapsulation in JavaScript

    I’ve had several discussion recently some of the more advanced features of JavaScript, such as functions as return values, namespaces, encapsulation, etc. In order to demonstrate some of these things, I contrived a simple example of a dependency injection tool. Never mind that dependency injection is not really a relevant pattern in JavaScript or other […]

  • Arrays as Objects in Javascript

    Rhino Prompt… js> a[0] = 1; js> a.print = function () {for(var e in this) print (“a[” + e + “] = ” + a[e]);}; function () { for (var e in this) { print(“a[” + e + “] = ” + a[e]); } } js> a.print(); a[0] = 1 a[print] = function () { […]