24.10.2014 Views

Hafez Rouzati

Hafez Rouzati

Hafez Rouzati

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Scope<br />

// Global variables are global<br />

var GLOBAL_VAR;<br />

// anonymous / immediate function (code inside is called as soon as evaluated<br />

(function(){<br />

// local to inner scope<br />

var local_to_function;<br />

})();<br />

init();<br />

// object literal syntax<br />

var dog = {<br />

! name: "Lassie",<br />

! getName : function () {<br />

! ! return this.name;<br />

! }<br />

};<br />

// Function “Object” syntax<br />

function Person(params) {<br />

! this.name = params.name;<br />

! this.address = params.address;<br />

! this.id = 1234567;<br />

};<br />

// Extending the Person prototype<br />

Person.prototype.sayHi = function() {<br />

! console.log("Hi my name is " + this.name);<br />

};

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!