原型链 继承
charCodeAt()
charCodeAt() 方法可返回指定位置的字符的 Unicode 編碼。這個(gè)返回值是 0 - 65535 之間的整數(shù)。
var str = "123abc張文強(qiáng)"; var n = str.length; function byteLength(str) {// for(var i = 0; i < str.length; i++) {// if(str.charCodeAt(i) > 255) {// n++;// }// }// return n;var count = 0;for(var i = 0; i < str.length; i++) {if(str.charCodeAt(i) > 255){count += 2;}else{count ++;}}return count; }原型
prototype----- >原型(相當(dāng)于父親)
例如:
new 的時(shí)候,創(chuàng)建 var this ={__ proto __:Person.protortype}
原型鏈
簡(jiǎn)單的原型鏈樣例:
Grand.prototype.lastName = "Deng"; function Grand() {} var grand = new Grand();Father.prototype = grand; function Father() {this.name = 'xuming'; }var father = new Father();Son.prototype = father; function Son () {this.hobbit = 'smoke'; } var son = new Son();yuanxianglianyangtti
//a.sayName()執(zhí)行 //sayName里面的this指向誰(shuí),誰(shuí)調(diào)用的這個(gè)方法,this就是指向誰(shuí) //所以這個(gè)提題的答案是 b; Person.prototype = {name : "a",sayName : function () {console.log(this.name);} } function Person () {this.name = "b"; } var person = new Person();Object.creat(原型)
例如:
obj = { age : 20,name : "zhang" } obj1 = Object.creat(obj);再例如:
Person.prototype.name = "sunny";function Person() {//這里面寫(xiě)東西的話(huà)就不能模仿了}var person = Object.creat(Person.prototype);大多數(shù)對(duì)象都會(huì)繼承于Object.prototype;
當(dāng)Object.creat (null)時(shí),它就沒(méi)有__proto__;
對(duì)象
var zhang { name : "xiaoqiang",sex : "male",age : "19",gf : "none",wife : "",getMarried : function() {this.wife = this.gf;},divorce : function() {delete this.wife;this.wife = this.pre}}包裝類(lèi)
原始值沒(méi)有對(duì)象和方法,包裝類(lèi)會(huì)起作用,創(chuàng)建一個(gè)
new Object().sign = ‘xxx’;
new Object().sign;
parseInt();
parseInt() 函數(shù)可解析一個(gè)字符串,并返回一個(gè)整數(shù)(十進(jìn)制)。
有兩個(gè)值前面是要解析的字符串,后面是禁制如果不寫(xiě)或者為0的話(huà)默認(rèn)為10;
例如:
后面的值:
- 可選。表示要解析的數(shù)字的基數(shù)。該值介于 2 ~ 36 之間。
- 如果省略該參數(shù)或其值為 0,則數(shù)字將以 10 為基礎(chǔ)來(lái)解析。如果它以 “0x” 或 “0X” 開(kāi)頭,將以 16 為基數(shù)。
- 如果該參數(shù)小于 2 或者大于 36,則 parseInt() 將返回 NaN。
arguments[];
function test(x, y, a){a = 10;console.log(arguments[2]); } test(1, 2 ,3); function test(x, y, a){arguments[2] = 10;console.log(a);}test(1, 2, 3);上面這兩串代碼的結(jié)果都一樣都是 10 ;
argunment[]和行參里面的值是一一對(duì)應(yīng)的關(guān)系(你動(dòng)我就動(dòng),我動(dòng)你也動(dòng));
字符串有一個(gè)方法charCodeAt();
構(gòu) 造 函 數(shù)
函數(shù)名第一個(gè)字母大寫(xiě)加 new 函數(shù)體的最前面隱式的加上 this={ };最后加上return this; function Car() {this.owner = owner;this.carName = "BMW";this.height = 1400;this.lang = 4900;this.color = color; } var car = new Car('zhang','red');經(jīng)典例題
var obj = {name : "a"}; var obj1 = obj; obj = {name : "b"}; //問(wèn)現(xiàn)在console.log(obj1);輸出是什么? //結(jié)果是 a ;總結(jié)
- 上一篇: 借助YunOS ,开发技术、运营能力大幅
- 下一篇: GO Web编程---网上书店(1)