什么是oo继承,什么是扁平化,javascript 是怎么样实现的,麻烦说的详细些,不要复制别人的东西啦

JavaScript016

什么是oo继承,什么是扁平化,javascript 是怎么样实现的,麻烦说的详细些,不要复制别人的东西啦,第1张

js继承有三种方式:原型继承,复制继承,伪装继承。其中使用最多的是原型继承,也就是oo继承,例:

function Animal() {

    this.color = 'black'

}

function Cat() {

    this.legs = 4

}

Cat.prototype = new Animal()//Cat 就继承了Animal的属性color

var cat = new Cat()

console.log(cat.color)//black

扁平化应该指的是json对象扁平化,也是刚查到资料的,详情请见这个:http://www.2cto.com/kf/201111/112558.html

//先定义个对象:

var oo={href:"默认值", title:"""}

//定义数组

var arr=new Array();

$(function(){

$('.library img').each(function(){

var _this = $(this)

oo.href = _this.attr('src')//对象赋值

oo.title = _this.attr('title')

arr. push( oo ) //加入数组

})