Skip to content

Instantly share code, notes, and snippets.

@dannycroft
Created January 14, 2015 12:06
Show Gist options
  • Save dannycroft/1f96373267c91718d7c2 to your computer and use it in GitHub Desktop.
Save dannycroft/1f96373267c91718d7c2 to your computer and use it in GitHub Desktop.
function Words(str) {
this._str = str;
}
Words.prototype[Symbol.iterator] = function() {
var re = /\S+/g;
var str = this._str;
return {
next: function() {
var match = re.exec(str);
if (match) {
return {value: match[0], done: false};
}
return {value: undefined, done: true};
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment