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) 编辑 收藏 举报