Difference between revisions of "Javascript"
| Line 1: | Line 1: | ||
===OOP=== | ===javascript OOP using Literal Notation=== | ||
Literal Notation seems much more readable to me. | Literal Notation seems much more readable to me. | ||
====OOP single==== | ====OOP single==== | ||
Revision as of 16:44, 27 March 2013
javascript OOP using Literal Notation
Literal Notation seems much more readable to me.
OOP single
In cases where you don't need multiple instances of a Class, then it is easy to create a object like this: <syntaxhighlight>
var obj={
tisel : new Array(),
tesel : "" ,
ulsel : '.prog-tes ul',
lisel : '.prog-tes ul li',
idx : 0,
arr : new Array(),
new : function(){
this.tesel="dog";
this.tisel[0]="cat";
return "frog";
}
};
obj.new();
</syntaxhighlight> You declare all your variables. Make a fake new or constructor to initalize.
OOP multiple instances
If you need multiple instances of a class (many objects) and you want to use literal notation then you could do it like this <syntaxhighlight>
anima=new Object();
anima.large = "elephant"
anima['small'] = "mouse";
feline=new Object();
feline[4]=anima;
function MyClass(animal,feline){
this.tesel=animal;
this.tisel=feline;
return "frog";
}
MyClass.prototype={
ulsel : '.prog-tes ul',
lisel : '.prog-tes ul li',
idx : 0,
arr : new Array(),
new : function(){
console.log(this.tesel);
this.tesel="jerk";
this.tisel[17]="drugs";
this.tisel[0]="rock";
}
};
obj=new MyClass(anima,feline);
</syntaxhighlight>
JSON Objects and Arrays
Use objects ...but... Objects treat indexes like an association.
- arr[4]="dog" [ , , ,"dog"]
- obj[4]= object [4:"dog"]
_SESSION variables
The problem with having stuff happen on the server is that it always forgets what is going on from moment to moment. The server waits for a request, it could be from anywhere in the world. It doesn't know you from a whole in the wall. The only thing you can do to be remembered is stick stuff in _SESSION variables.
http://www.javascript-coder.com/javascript-form/javascript-get-form.htm