Skip to content

Instantly share code, notes, and snippets.

View kensnyder's full-sized avatar

Ken Snyder kensnyder

View GitHub Profile
// Truncate a string to the closest word
String.prototype.truncateToWord = function(len) {
return (len = Number(len)) >= 0 ?
this.match(new RegExp('^([\\s\\S]{0,' + len + '})(:?\\s|$)'))[1] :
undefined;
};
// Examples
// The "v" marks the first character out of bounds.
// Prototype object that works a lot like jQuery:
var NodeList = Class.create(Enumerable);
Object.extend(NodeList.prototype, {
initialize: function(selector) {
this.elements = $$(selector);
},
_each: function(iterator) {
this.elements.each(iterator);
return this;
}
// Prototype object that works a lot like jQuery:
var NodeList = Class.create(Enumerable);
Object.extend(NodeList.prototype, {
initialize: function(selector) {
this.elements = $$(selector);
},
_each: function(iterator) {
this.elements.each(iterator);
return this;
}