定义:
在函数体中定义另外的函数作为目标对象的方法函数,而目标对象的方法函数,调用外层函数中的临时变量:
例如:
function Person(firstName, lastName, age)
{
this.age = age;
this.getName = function()
{
return(firstName + " " + lastName);
};
this.SayHello = function()
{
alert("Hello, I'm " + firstName + " " + lastName);
};
};
var BillGates = new Person("Bill", "Gates", 53);
var SteveJobs = new Person("Steve", "Jobs", 53);
BillGates.SayHello();
SteveJobs.SayHello();