Difference between revisions of "Javascript"

From Wiki2
Line 1: Line 1:
[http://www.mikedoesweb.com/2012/creating-your-own-javascript-library/ creating library]
[http://www.impressivewebs.com/callback-functions-javascript/ callback]
{{:frameworks}}
{{:frameworks}}



Revision as of 23:04, 25 March 2014

creating library

callback




js frameworks

react

https://github.com/securingsincity/backbone-react-ui

angularJS

backbone

mongodb

node

meteor

ember

plan

use yeoman

   mkdir my-app
   cd my-app
   npm install generator-angular
   yo angular

in Gruntfile.js change connect: hsotname: from 'localhsot' to '10.0.1.24' so it will run on LAN

   grunt serve


rewrite stuff2get using angular

<syntaxhighlight lang="javascript">

   it('sends a timestamp to a sever every time you push a button', function() {});

</syntaxhighlight>

design patterns

javascript tutorials by Crockford

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=new Array();
       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> The stuff above function Myclass is just junk to try to see the diffferences between arrays and objects.

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