Permalink
Browse files

Use trim with polyfill.

  • Loading branch information...
rniemeyer committed Feb 26, 2012
1 parent 6bfa658 commit 2b702c938403225bc161759c0256a8937643db79
Showing with 8 additions and 1 deletion.
  1. +8 −1 architecture-examples/knockoutjs/js/app.js
@@ -1,4 +1,11 @@
(function () {
+ //trim polyfill
+ if (!String.prototype.trim) {
+ String.prototype.trim = function () {
+ return this.replace(/^\s+|\s+$/g, '');
+ };
+ }
+
//a custom binding to handle the enter key (could go in a separate library)
ko.bindingHandlers.enterKey = {
init:function (element, valueAccessor, allBindingsAccessor, data) {
@@ -78,7 +85,7 @@
//add a new todo, when enter key is pressed
self.add = function (data, event) {
- var newTodo, current = (self.current() || "").replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, "");
+ var newTodo, current = self.current().trim();
if (current) {
newTodo = new Todo(current);
self.todos.push(newTodo);

0 comments on commit 2b702c9

Please sign in to comment.