Created
December 23, 2013 15:40
-
-
Save zzuhan/8099181 to your computer and use it in GitHub Desktop.
sub.js 字符串替换
截取自YUI.Lang.sub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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