JavaScript Intensive Tutorial-js Object-oriented programming

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.