Sunday, June 14, 2009

Javascript Basics......

Its been long time since I wrote a post. Was busy with lot of things.
Lately I have been working a lot with Javascript. This is the first time I am using Javascript heavily in a project.

Today I want to demonstrate some of the basic javascript concept.
1)Static Methods
2)Public Methods/Variables
3)Private Methods/Varables


In this project.. I created a simple server control which renders a link. Href of this link is a javascript function.



Javascript method CreateArt(...) creats an instance of a Window Object.
var win = new Window();

Window object'ss prototype property has two methods
1)Initialize(..) -- Sets the local variable firstName,middleName,lastName
2)Display(..) -- Displays the names in a table which is attached to the body of the document.





Another way to set the prototype is to add each function individually.




adding public variable/function and a private variable/function to the Window Object.




Declaring a public method is done using the this keyword.

Private methods are declared using a private Variable and then adding a method to that variable. The advantage of this is we dont expose this method from the class.

Static Method can be easily declared by adding that method to the class. for eg:


If you want to download the source code please click here --> http://dotnetdevblog.googlepages.com/JavascriptBlogApp.zip
I started loving javascript as a language after working on this project. I used to think javascript was not for real programmer but now I believe it has lot of goodness in it.
Embrace It :)
Thanks,
Yash





0 comments: