function Person(name,age,job){ this.name = name; this.age = age; this.job = job; this.sayName = function(){ alert(this.name); } }
1、当作构造函数使用
var person = new Person("zhangsan",28,"teacher"); person.sayName(); //zhangsan
2、作为普通函数调用
Person("lisi",32,"doctor"); //添加到window window.sayName();
3、在另一个对象的作用域中调用
var o = new Object(); Person.call(o,"wangwu",21,"Nurse"); o.sayName();