<script>
function Father() {}
Father.prototype.feel=function(){
console.log('荏苒');
}
function.Son(){}
Son.prototype=new Father();
Son.prototype.think=function(){
console.log('时光');
}
Son.prototype.touch=Son;
console.log=new Son();
var obj=new Son();
obj.think();
obj.feel();
</script>
我的理解
function Father() { } //声明一个 Father函数
Father.prototype.feel = function () { //给 Father原型上加一个 feel函数 。
console.log('荏苒');
}
function Son(){ } //声明一个 Son函数
Son.prototype = new Father(); //给 Son原型 加一个 实例化 的 Father函数
Son.prototype.think = function () { //给son的原型 加一个 think函数
console.log('时光');
}
Son.prototype.touch = Son; //给son的原型加一个 touch 并且赋值为son
//console.log = new Son();
var obj = new Son(); //实例化 Son
obj.think(); //调用 son下的 think方法
obj.feel();//调用 son下的 feel方法 son下的feel实际上是Son.prototype = new Father(); 赋值过来的
上面解答的注释已经可以解决你的疑惑了。
涉及的知识点是关于原型链的知识。
如果你感兴趣的话可以看看我写的博文,看完了你就能自己读懂这段代码了。