Java Script ,OOP
Now , this is something that is worthwhile to take a look and have a good understanding.
Most of most that use the higher level of API build on top of Asp.net 2.0, Will rarely use client side scripting, so many people that even start jump to asp.net but does not even know what html is. but really at the end what you eventually will produce is merely HTML,DHTML and JavaScript.
I bet those that talk a lot about this and that technology still lacking of the fundamental concept.
this is the trickiest interpreter language, lousiest.
- Even Function return as Object,
- every thing works with name value pair { xxx:value }
- If you haven't declare a method or member of a class,the interpreter will create it for you and it becomes global , on window.youmember
function test() { foo = "test";
}
test();
alert(window.foo == "test");
- You can change the Execution Context by functionname.call(context,param1,n) or functionname.apply(context,param1,n)
When EcmaScript interpret your code, it has the internal [[scope]] property that make a chain scope, the last scope only contains the global object. Scope can be Global, belongs to the window object. or Private , belongs inside a function
The prototype also make a chain , if an object refer to another one object, it keeps searching for it.Lastly the script will try to get the value into string if you access the value. while it build the variable/activation object the interpreter add arguments property that you can access inside any function .
Closures
an inner function that use and manipulate the outer function variable member or parameter.because of this comes the private and public member
Public Member
You can set directly on the
constructor
1: Function user(name,age)
2:
3: { 4:
5: this.name=name;
6:
7: this.age=age;
8:
9: }
10:
or by attaching on prototype
user.prototype.getname()=function{return this.name;};
Private Member Go here
Static method
Object.Staticmethodname=function{//your code here};
Can Javascript do Inheritance and Polymorphism?
Yes , with a little help from some wrapper, You can choose:
- Crockford Helper to refer to the base class function use the this.uber('functionname')
- DeanEdwards Base Lib this is more readable, since like if we want to refer to the base class function , just use this.base() , it will figure out itself which method
- Prototype Library
Name Space and Packaging
- Dojo Framework: dojo.js 77kb, include Ajax, widget, namespace ,etc.check it out
- YUI. yahoo user interface