JavaScript Object-Oriented Concept Essential Part1
1. Everything excpet primitive types in JavaScript is object.
2. Primitive types include Undefined, Null, Boolean, Number and String.
3. JavaScript has three kinds of objects.
6. this is used to refer the current object.
7. class in Javascript is defiend as function.
Ex, var primitiveString = "I am string varible" ;
primitiveString.prop = "my property"; // this is wrong
While var stringObj = new String("make a string object");
stringObj.prop = "my property"; //this is correct
2. Primitive types include Undefined, Null, Boolean, Number and String.
3. JavaScript has three kinds of objects.
- 3.1 Build-in objects: Array, Image, Date...
- 3.2 Host objects: window, document, forms..
- 3.3 User-defined.
- Ex, var stringObj = new String("create String object");
6. this is used to refer the current object.
7. class in Javascript is defiend as function.
- class field and function is defined by this. Ex,
- function Cicle(radius){
- this. radius = radius; // defined class field, assigned by parameter of constructor
- this. getArea = getArea; // defined class function, getArea is a function
- function getArea(){return this. radius;}// still use this to refer current object
- //the function getArea can also be defiend outside the class, with this. radius always
- //refer the object who use the funtion.
- }
- 8.1 functionName = function("para1","para2");// the last para is the body of the //function, you can use the functionName as the callable block, and it is an object
- 8.2 var myFunctionObj = new Function();
- 8.3 var myFunctionObj = Function();
- 8.4 var myFunctionObj = function(){};
- 8.5 function myFunctionObj(){};
Ex, var primitiveString = "I am string varible" ;
primitiveString.prop = "my property"; // this is wrong
While var stringObj = new String("make a string object");
stringObj.prop = "my property"; //this is correct
评论
发表评论