Created
May 6, 2012 04:39
-
-
Save petermichaux/2613483 to your computer and use it in GitHub Desktop.
TodosModel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
It doesn't create a global. It adds a constructor function to the provided namespace object which, in this case, is the checkit object.
My mistake, why does it strip the "Model" of the name of the constructor?
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
What's the rational for
subclass
to create a global variable rather then for it to return the new class ?