Saturday, February 6, 2010

Object Oriented JavaScript and C#

Just started to work on object oriented java script language, and realized its whole new world of world of programming. You can define the properties (member variables) and methods for objects, and objects of the JavaScript are Dictionary. As its dictionary, it will be collection of name/value pairs. Below is the example –

JSObject = new Object();

You don’t need to define Property beforehand, you can directly initialize it directly.

JSObject.property1 = new Date();

alert('this is property property1 :' + JSObject.property1);

Same with the method –

JSObject.func1 = function() { alert ('this is method func'); }

JSObject.func1();

This is just a basic example, you can create the full workflow of the script page, and handle all the operations in backend.

JSObject2 = { Property1 : "Test",

Method1 : function() {alert("Test method1 function");}

You can register the script on the back endd and execute on the page load –

if(!Page.ClientScript.IsStartupScriptRegistered("myTest"))

Page.ClientScript.RegisterStartupScript(this.GetType(), "myTest", "Test()",true);

This is just simple OOP JS example, you can do many more thing in client side and take advantage of JS. ExtJS library is another extended world of JavaScript. I will explore more things, and post few more examples and features of capabilities of JavaScript.