javascript - 一道js面试题;
本文介绍了javascript - 一道js面试题;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
说明以下函数是做什么用的;
补全空白处的代码
(function(window) {
function fn(str) {
this.str = str;
}
fn.prototype.format = function() {
var arg = ____;
return this.str.replace(____, function(a, b) {
return arg || '';
})
};
window.fn = fn;
})(window)
// use
var t = new fn('[1][2]');
console.log(t.format('http://Alibaba.com','alibaba','welcome'))
解决方案
格式化文本。
string.Replace用法
这篇关于javascript - 一道js面试题;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文