<!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>
<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>
{
if(obj.hasOwnProperty(key)){ // 添加一个判断key是否是自身属性就可以解决这个问题。
console.log('key');
console.log(key);
console.log('obj');
console.log(obj);
this.__proto__[key]=obj[key];
}
}
}