Skip to content

Instantly share code, notes, and snippets.

@petermichaux
Created May 6, 2012 04:39
Show Gist options
  • Save petermichaux/2613483 to your computer and use it in GitHub Desktop.
Save petermichaux/2613483 to your computer and use it in GitHub Desktop.
TodosModel
maria.SetModel.subclass(checkit, 'TodosModel', {
methods: {
getDone: function() {
return this.filter(function(todo) {
return todo.isDone();
});
},
getUndone: function() {
return this.filter(function(todo) {
return !todo.isDone();
});
},
markAllDone: function() {
this.forEach(function(todo) {
todo.setDone(true);
});
},
markAllUndone: function() {
this.forEach(function(todo) {
todo.setDone(false);
});
},
deleteDone: function() {
this['delete'].apply(this, this.getDone());
}
}
});
// ----
//
// var todos = new checkit.TodosModel(); // create a todos set
// todos.add(new checkit.TodoModel()); // add a todo to the set
@Raynos
Copy link

Raynos commented May 6, 2012

What's the rational for subclass to create a global variable rather then for it to return the new class ?

@petermichaux
Copy link
Author

It doesn't create a global. It adds a constructor function to the provided namespace object which, in this case, is the checkit object.

@Raynos
Copy link

Raynos commented May 6, 2012

My mistake, why does it strip the "Model" of the name of the constructor?

@petermichaux
Copy link
Author

That was a mistake in the commented code at the bottom. Fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment