- function Box(name, age) { //构造函数模式
- this.name = name;
- this.age = age;
- this.run = function() {
- return this.name + this.age + '运行中...';
- };
- }
- var box1 = new Box('Lee', 100); //new Box()即可
- var box2 = new Box('Jack', 200);
- alert(box1.run());
- alert(box1 instanceof Box); //很清晰的识别他从属于 Box
来源: http://lib.csdn.net/snippet/javascript/39144