An abstract description of things
describe the characteristics and behavior of such things
object is an instance of a class
code implementation: Creating a Class
function peple () { this.hp=0; this.act = 30; this.name = ""; this.x=0; this.y=0; this.move =function (x, y) { document.write (this.name+ "Moving to" +x+ "," +y "); } this.eat=function () { document.write ("eating"); } }
Instance of class: Creating an Object
var p1 = new Peple (); P1.name= "Ada"; P1.HP = 100; P1.move (100,100); P1.move (22,200);
[b] Dynamic extension method outside the class [/b]
P1.fire = function (x, y) {document.write (this.name+ "is firing to" +x+ "," +y "); p1.hp--; }
Calling functions defined outside the function
P1.fire (00,00); P1.fire (43,22); P1.fire (66,88); document.write ("hp=" +p1.hp);
Click to enter: JS Intensive tutorial
This article is from the "11722655" blog, please be sure to keep this source http://11732655.blog.51cto.com/11722655/1790311
JavaScript Intensive Tutorial-js Object-oriented programming