나는 자바 스크립트를 배우고 Knockout.JS의 예에서이 코드를 건너 왔어요 오전 : 나는이 권리를 이해한다면학습 자바 스크립트 : 쉼표로 멤버 배열 선언?
var viewModel = {
people: [
new Person("Annabelle", ["Arnie", "Anders", "Apple"]),
new Person("Bertie", ["Boutros-Boutros", "Brianna", "Barbie", "Bee-bop"]),
new Person("Charles", ["Cayenne", "Cleopatra"])
],
showRenderTimes: ko.observable(false)
};
는, '사람' '사람'객체의 배열을 포함하는 멤버 변수입니다. 그러나 배열 뒤에 콤마가 오는 이유는 무엇입니까? 'showRenderTimes'가 클래스에서 선언 된 다음 멤버 변수가 아닌가? 아니면 '국민'회원의 일부 확장인가? 그 콤마가 세미콜론이 아닌 이유는 무엇입니까?
여기 당신이 그것을 필요로하는 경우의 전체 목록입니다 : people
및 showRenderTimes
: 여기
var Person = function(name, children) {
this.name = name;
this.children = ko.observableArray(children);
this.addChild = function() {
this.children.push("New child");
}.bind(this);
}
// The view model is an abstract description of the state of the UI, but without any knowledge of the UI technology (HTML)
var viewModel = {
people: [
new Person("Annabelle", ["Arnie", "Anders", "Apple"]),
new Person("Bertie", ["Boutros-Boutros", "Brianna", "Barbie", "Bee-bop"]),
new Person("Charles", ["Cayenne", "Cleopatra"])
],
showRenderTimes: ko.observable(false)
};
$(document).ready(function() {
// Define a "Person" class that tracks its own name and children, and has a method to add a new child
ko.applyBindings(viewModel);
});