我不确定解决这个问题的正确方法,因此我希望你就此事发表意见。我想拥有如下所示的实例集合:
Person P = new Person();
P.Name = 'John';
P.Surname = 'Dough';
var People = [];
People.push(P);
这可以用Javascript(或Jquery,Angular ..)编写上面的代码吗?我可以关注或阅读的任何博客?
答案 0 :(得分:1)
如何定义Person
“class”:
var Person = function() {
};
var P = new Person();
P.Name = 'John';
P.Surname = 'Dough';
var People = [];
People.push(P);
或没有function
- 仅使用简单的对象:
var P = {
Name: 'John',
Surname: 'Dough'
};
var People = [];
People.push(P);