malaikuangren

What is the purpose or drive to build thing like (xxx),How can it achieve the original goal of design?
What's the best way to define a class in javascript
// Define a class like this
function Person(name, gender){

   // Add object properties like this
   this.name = name;
   this.gender = gender;
}

// Add methods like this.  All Person objects will be able to invoke this
Person.prototype.speak = function(){
    alert("Howdy, my name is" + this.name);
}

// Instantiate new objects with 'new'
var person = new Person("Bob", "M");

// Invoke methods like this
person.speak(); // alerts "Howdy, my name is Bob"

 

 

 

See detail:

http://stackoverflow.com/questions/387707/whats-the-best-way-to-define-a-class-in-javascript

posted on 2013-03-22 15:20  malaikuangren  阅读(147)  评论(0编辑  收藏  举报