Category Archives: Javascript

Interesting Assignment Related to Rich Internet Controls

One or my recent projects was to work with a client to create a Silverlight control for reporting purposes that has some general flashiness, and is reusable across several sections of the site. It has brushed into some interesting areas. I have used Silverlight for some media and imaging applications before, but this was the first that the control had to integrated with the authorized users profile and other security related server side settings.

In particular, the first thing to keep in mind is that as long as the Silverlight Enabled WCF endpoint is within the web application on IIS, then the service code has access to the users profile info. It’s just as if making a jquery request from a page, there is no need for the Silverlight control to re-authenticate.

The really interesting part is where the project goes from here. The client has asked me to create an equivalent control using HTML 5 technologies. There will be some lunch and learn sessions on how both of these projects were done, and comparing and contrasting both the user experience and developer experience.

I’m excited about doing this type of work for a variety of reasons. First, the training aspect really helps our company differentiate from other consulting companies, especially from rent-a-coder staff augmentation type shops. And I enjoy the challenges and rewards that come with helping other developers work with tools that are new to them. Finally, the very question we’re addressing (plugin vs standards based RIA controls) is on the forefront of lot of minds, given the current state of browser and mobile applications.

Anyway, this is just a general update of what I’m up to, but I hope this work will spin off some presentations I can do locally, and some blog posts.

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 dynamic languages. It just fit all the pieces I wanted to demo. The Rhino JavaScript engine was used to run and test the example.

For more on how this stuff works, check out Douglas Crockford’s JavaScript: The Good Parts

//ObjectMap namespace
var ObjectMap = function (){
    var that = this;

    that.container = function () {
        var registry = {};
        var fact = {};

        fact.register = function (name, constructor) {
            registry[name] = constructor;
        };

        fact.getObject = function (theType) { 
            return registry[theType]();
        };
        return fact;
    }();
   
    return that;
}();

//Dog constructor, with encapsulated private name
var Dog = function () {
    var d = {};
    var name = "spot";
    d.getName = function () {return name;};
    d.setName = function (val) {name=val; return d;};
    d.speak = function () {return d.getName() + " barks";};
    return d;
};

//register Dog with the DI tool
ObjectMap.container.register("Dog", Dog);

//get and use an object function the DI tool 
var munson = ObjectMap.container.getObject("Dog");
munson.setName("Munson");
print(munson.speak());

Integrating Internet Services on Your Site (Or Mini-Cloud Web Sites)

Something I’ve been increasingly fascinated with over the last year is the reuse of free internet services that I have. On my site, I have widgets that feed the last 4 posts from this wordpress blog, and my twitter feed. I also have an ajax live bing search box that will return results from my site, or the web in general. Most recently, I setup my default page to show a random image from a set I have on flickr.

Separately, over on linkedin, any blog posts that I tag “linkedin” show up. And I have a google docs presentation integrated into my profile. All of these integrations were free, and pretty easy to do. Many of them involved copy and paste html. A few involved calling api’s, but they were easy to use and well documented.

And I haven’t touched the tip of the iceberg. Last.fm, Delicious, google calendar, and more all provide feeds and widgets that I’m not yet taking advantage of. And there are creative ways to use these differently than intended.

It’s easy to write a twitter widget, that doesn’t appear to be twitter. Drop it on a client’s site, and they can add news blurbs via twitter or sms. It’s a small piece of content management that couldn’t be easier to integrate.

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 () {
    for (var e in this) {
        print("a[" + e + "] = " + a[e]);
    }
}