<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script language="javascript">
var message={};
//后面的函数在包含在方括号内,方便用push添加新的函数,这样写法相当于message={test:[function(e){console.log('hi'+e.msg)}]}
message['test']=[function(e){
console.log('hi '+e.msg);
}];
message.test.push(function(e){
console.log('hello '+e.msg);
});
var i=0,len=message['test'].length,events={msg:'tom'};
//循环添加参数到对象内部的函数内
for(;i<len;i++){
message['test'][i].call(this,events);
}
console.log(message);
</script>
</body>
</html>
javascript向对象内添加函数的方式
最新推荐文章于 2024-09-29 17:29:06 发布