<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
function a() {
console.log("I'am a function.");
}
//b是实例化对象,a是构造函数
var b = new a();
//console.log(b.__proto__)
var $ = function() {
extend = function(obj)
{
console.log(obj)
console.log('扩展')
for(var key in obj)
{
console.log('key');
console.log(key);
console.log('obj');
console.log(obj);
this.__proto__[key]=obj[key];
}
}
return { extend : extend };
}();
$.extend({
myFunction:function(obj)
{
console.log('我函数')
}
})
console.log('第二次')
$.extend({
showScreen:function(obj)
{
console.log('展示的大屏幕')
}
})
$.showScreen();
$.myFunction();
</script>
</body>
</html>
我每次只是增加一个key
第二次增加的key不包括第一次的key
但是第一次的key还是显示出来了
因为你为
this.__proto__
添加了myFunction
和showScreen
两个key啊...在遍历的时候就会输出两个呐...那我改出来一个大致能满足你的需求的版本,你可以瞧一眼...