<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
var o1 = {};
var o2 ={ name:'jim'};
o1.name =o2.name;
console.log(o1.name);
function extend(o1,o2){
for(var k in o2){
o1[k] =o2[k];
}
}
var o1 = {name:'jim'};
var o2 ={
age: 16,gender:'male' };
extend(o1,o2);
console.log(o1.name);
console.log(o1.age);
function Person(options){
extend(this,options);
}
Person.fn =Person.prototype;
Person.fn.extend =function(obj){
extend(this,obj);
};
Person.fn.extend({
sayHello: function(){
console.log('你好,我是'+(this.name|| '无名'));
}
});
var p1 =new Person();
var p2 =new Person({name:'张三',age:16});
p1.sayHello();
p2.sayHello();
</script>
</body>
</html>
混入继承
最新推荐文章于 2023-03-26 19:08:28 发布