//&&得到的结果不是布尔类型,如果前面都是 true就执行最后一个,并返回最后一个表达式的值,前面有一个为false,后面不执行,返回前面表达式的值var a = 3;var b = a && (a = 4);console.log(b);//4var b = a && (a ++);console.log(a);//5console.log(b);//4a && (a ++);console.log(a);//6var c = 0;var d = c && a++;console.log(a);//6console.log(d);//0var c = 0;var d = b && c && a++;console.log(a);//6console.log(d);//0var c = false;var d = b && c && a++;console.log(a);//6console.log(d);//false// || 前面是true,后面不执行,返回前面表达式值。前面是false,返回后面表达式的值var a1 = 3;var b1 = a1 || a1++;console.log(a1);//3console.log(b1);//3var a1 = 0;var b1 = a1 || a1++;console.log(a1);//1console.log(b1);//0====================================================================//浅拷贝,指向同一个内存区域var person ={ name:"cj", age:22, address:{ home:"home address", office:"office address" }, schools:["xiaoxue","daxue"] };var programer = { language:"javascript" };//全部复制function extend (p,c) { var c = c ||{}; //如果c是undefined或者null,就是{} for(var prop in p){ c[prop] = p[prop];//如果有属性值是对象,则是把地址复制过去了, }}extend(person,programer);console.log(programer.address);//{home: "home address", office: "office address"}console.log(programer.address.home);//home addressconsole.log(programer.schools);//["xiaoxue", "daxue"]programer.name = "sss";console.log(person.name);//cjprogramer.address.name = "xxx";console.log(person.address.name);//xxxprogramer.schools[0] = "iii";console.log(person.schools[0]);//iiiconsole.log(person.schools[0]);//iii=====================================================//深拷贝,跟父类没关系了function extendDeeply(p,c){ //from --> to var c = c|| {}; for(var prop in p){ //{}形式的对象可以用for in循环,prop是key,p[prop]是每一个value。json和数组都可以用for in循环,数组时候prop是0,,1,2,3,json时候prop是key if(typeof p[prop] === "object"){ c[prop] = (p[prop].constructor ===Array)?[]:{};//c[address]={} extendDeeply(p[prop],c[prop]);//p[address],c[address] }else{ c[prop] = p[prop];//给c新增一个key和value,c[address][home]=p[address][home] } }}================================================================function Parent(){ this.name = "abc"; this.address = {home:"home"};}function Child(){ //可以看成类,对象,构造函数,函数执行是相当于构造函数执行但是要return function才产生对象。 Parent.call(this);//this就有了Parent的属性了,深拷贝 this.language = "java";}var c = new Child();c.address.home = "ssss"var p = new Parent();console.log(p.address.home);//home================================================================= //原型链;java里面的继承关系,一直找到Object类去 var p ={name:"cj"}; function myCreate(p){ var ins ; function F(){}; F.prototype = p;//函数的原型指向p对象,函数公有区域指向p对象,所以ins.__proto__指向p对象,就实现了继承。 ins = new F(); return ins ; }//对象的__proto__ 指向的是//对象的构造器constructor//的原型对象(prototype)//但原型对象并不是能用上面的话来说明//原型对象的__proto__指向的是Object得prototype//而不是指向//其(Object.prototype)构造器constructor ==某个函数//的原型对象
function FF(){}; var ff = new FF(){}; ff.__proto__ === FF.prototype;//true ff.__proto__ === ff.constructor.prototype; //true FF.prototype.__proto__ ===FF.prototype.constructor.prototype; //false