Difference between revisions of "Javascript"

From Wiki2
Line 1: Line 1:
===OOP===
===OOP===
Literal Notation seems much more readable to me.
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:
In cases where you don't need multiple instances of a Class, then it is easy to create a object like this:
<syntaxhighlight>
<syntaxhighlight>
Line 20: Line 20:
</syntaxhighlight>
</syntaxhighlight>
You declare all your variables. Make a fake new or constructor to initalize.
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>
<syntaxhighlight>
         anima=new Object();
         anima=new Object();
Line 46: Line 49:
         obj=new MyClass(anima,feline);
         obj=new MyClass(anima,feline);
</syntaxhighlight>
</syntaxhighlight>
If you need multiple instances of a class (many objects) and you want to use literal notation then you could do it like this
 





Revision as of 17:44, 27 March 2013

OOP

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.

javascript tutorial

http://www.javascript-coder.com/javascript-form/javascript-get-form.htm

DOM

operators

ajax