首页 > Web开发 > 详细

js面试题-----原型和原型链

时间:2017-09-11 12:09:34      阅读:402      评论:0      收藏:0      [点我收藏+]

题目1:如何判断一个变量是数组类型

答案:

var arr = [];
arr instanceof Array//true
typeof arr //object  typeof 是无法判断数组的

题目2:原型链继承的例子(原型链继承,还有很多方法 参考我的js系列继承的6种方式)

答案:

function Animal(){
     this.eat = function(){
         console.log(‘animal  eat‘)

    }

}

function Dog(){
    this.bark = function(){
       console.log(‘bark‘)
    
     }

}

Dog.prototype = new Animal();

var hashiqi = new Dog()

题目3:描述new一个对象的过程

答案: ①、创建一个新对象 ②、this指向这个新对象  ③、执行代码,即对this赋值  ④、返回this

js面试题-----原型和原型链

原文:http://www.cnblogs.com/diasa-fly/p/7491060.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!