Skip to content

Instantly share code, notes, and snippets.

@zzuhan
Created December 23, 2013 15:40
Show Gist options
  • Select an option

  • Save zzuhan/8099181 to your computer and use it in GitHub Desktop.

Select an option

Save zzuhan/8099181 to your computer and use it in GitHub Desktop.
sub.js 字符串替换 截取自YUI.Lang.sub
var SUBREGEX = /\{\s*([^|}]+?)\s*(?:\|([^}]*))?\s*\}/g;
function isUndefined(val){
return typeof val === 'undefined';
}
var sub = function(s, o) {
return s.replace ? s.replace(SUBREGEX, function(match, key){
return isUndefined(o[key]) ? match : key;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment