Runtime modification of JavaScript Objects

Like many of us, I never learned the JavaScript formally but started dabbling in it, using a similar-looking language (Java) as base for my coding style. Here’s another feature that seems quite simple but it took me a while to realize how powerful it really is because of my Java bias. In Java or .Net, information about an object can be gathered and generic operations executed at runtime via a mechanism called Reflection. Since it adds a certain overhead and is cumbersome to code, it is used rarely in everyday code (although frameworks like Spring frequently use it internally). In JavaScript, on the other hand, it’s not only very easy to discover object details at runtime and perform operations in a generic way, but it’s even possible to add and remove object properties themselves.

Continue Reading →

Date posted: August 15, 2009

By Anke Doerfel-Parker

Categories: JavaScript

JavaScript Function Call() Operator

JavaScript has become one of my favorite languages. It is extremely flexible and powerful. It is not hard picking up the basics if you have programmed Java or C# before. But there are many features that are very hard to emulate or simply not possible in those languages. One example is the Function object’s call() operator. It allows execution of any function in the context of an object passed into the function, or, in other words, changing the this reference a function uses for the duration of the call.

Continue Reading →

Date posted: June 14, 2009

By Anke Doerfel-Parker

Categories: JavaScript

Connect with us: