Skip to content

Instantly share code, notes, and snippets.

String.prototype.template = function(obj) {
// dot notation path getter for array and obj
function objPath(obj, path){
var arr = path.split('.');
while (arr.length && obj) {
obj = obj[arr.shift()]
if(obj === undefined) return '{undefined '+path+'}';
}
jQuery.prototype.$cache = function(xpath, name) {
if (xpath.forEach) {
xpath.forEach(function(xp){
this.$cache(xp);
}.bind(this));
} else {
!name && (name = xpath.substr(1));
this[name] = this.find(xpath)
}
return this;