关于js 单列设计模式问题 请教下各位大神们

qq_36661519 qq_36661519 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
var getSingle=function(fn){
var result;
return function(){
return result||(result=fn.apply(this,arguments));
}
};
//创建单列--可变的部分
var creatDiv=function(height){
var div=document.createElement('div');
div.innerHtml='单列模式';
div.style.display='none';
div.style.height=height+'px';
document.body.appendChild(div);
return div
}
//创建
var createSingleDiv=getSingle(creatDiv);

document.getElementById('button').onclick=function(){
var login=createSingleDiv('100');
login.style.display='block'
}

把上面这段改成这样会出现关于apply的错误,哪位可以讲解一下谢谢~!



var getSingle=(function(fn){
var result;
return function(){
return result||(result=fn.apply(this,arguments));
}
})(creatDiv);
var creatDiv=function(height){
var div=document.createElement('div');
div.innerHtml='单列模式';
div.style.display='none';
div.style.height=height+'px';
document.body.appendChild(div);
return div
}

document.getElementById('button').onclick=function(){
var login=getSingle('100');
login.style.display='block'
}
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
qq_36661519
JavaScript 87,983 成员 224,681 内容