【发布时间】:2014-10-06 18:52:45
【问题描述】:
参考https://stackoverflow.com/a/387733/418439,
// 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"
namespace也怎么定义?
【问题讨论】:
-
JavaScript 中没有命名空间。
-
@wumm 确实没有,但你可以模拟它们。
标签: javascript oop javascript-namespaces