Javascript quick revisit


The new keyword

http://htmldog.com/guides/javascript/advanced/oo/
http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript

CDN - Content Delivery Networks

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>

Browser Object Model (BOM)

The window object is supported by all browsers. It represent the browser's window.

All global JavaScript objects, functions, and variables automatically become members of the window object.

Global variables are properties of the window object.

Global functions are methods of the window object.

Even the document object (of the HTML DOM) is a property of the window object:

window.document.getElementById("header");

same as:

document.getElementById("header");


RegEx

Syntax
var patt=new RegExp(pattern,modifiers);

or more simply:
var patt=/pattern/modifiers;


Prototype property
Prototype is a global constructor in JavaScript. It can construct new properties and methods for any JavaScript Objects.

Array.prototype.ucase=function(){
for (i=0;i<this.length;i++){
  this[i]=this[i].toUpperCase();}
}


Define JS object

direct:
person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"};

object constructor:
function person(firstname,lastname){
this.firstname=firstname;
this.lastname=lastname;

this.changeName=changeName;
function changeName(name){
  this.lastname=name;
}
}


OOP

JavaScript is an object oriented language, but JavaScript does not use classes. In JavaScript you don't define classes and create objects from these classes (as in most other object oriented languages). JavaScript is prototype based, not class based.

JS try-catch-throw

for...in statement loops through the properties of an object

Example:
for (x in person){
person[x];
}

Read object properties
var person={fname:"John",lname:"Doe",age:25};
name=person.lastname;
name=person["lastname"];

评论

此博客中的热门博文

AVR Tutorial - Input / Output

AVR ADC Analog to Digital Converter

Introduction to REST