有没有大神来解释一下这段JS的原理和相关知识

jan307 2015-04-07 09:26:29
var testJS = {};

function bindPrototype(name) {
testJS[name] = function ()
{
alert(name);
}
}
bindPrototype("test");
bindPrototype("test1");
bindPrototype("test2");

testJS.test();//alert test
testJS.test1();//alert test1
testJS.test2();//alert test2
...全文
106 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
姜小白- 2015-04-07
  • 打赏
  • 举报
回复
var testJS = {};
创建一个对象testJS

定义方法bindPrototype,传递name作为入参
function bindPrototype(name) {

指定testJS 的name属性为一个方法
testJS[name] = function ()
{
该方法弹出方法名称
alert(name);
}
}
bindPrototype("test");
绑定test方法

testJS.test();
执行test方法

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧