function createPerson(name, age, job) {
var obj = new Object;
obj.name = name;
obj.age = age;
obj.job = job;
obj.sayName = function() {
console.log(this.name);
};
return obj;
}
Component.onCompleted: {
var person1 = createPerson("Neo", 29, "Teacher");
person1.sayName();
var person2 = createPerson("Toby", 30, "Software Engineer");
person2.sayName();
}
输出结果: