原型链 继承
charCodeAt()
charCodeAt() 方法可返回指定位置的字符的 Unicode 編碼。這個返回值是 0 - 65535 之間的整數。
var str = "123abc張文強"; 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----- >原型(相當于父親)
 例如:
new 的時候,創建 var this ={__ proto __:Person.protortype}
原型鏈
簡單的原型鏈樣例:
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()執行 //sayName里面的this指向誰,誰調用的這個方法,this就是指向誰 //所以這個提題的答案是 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() {//這里面寫東西的話就不能模仿了}var person = Object.creat(Person.prototype);大多數對象都會繼承于Object.prototype;
 當Object.creat (null)時,它就沒有__proto__;
對象
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}}包裝類
原始值沒有對象和方法,包裝類會起作用,創建一個
new Object().sign = ‘xxx’;
 new Object().sign;
parseInt();
 parseInt() 函數可解析一個字符串,并返回一個整數(十進制)。
 有兩個值前面是要解析的字符串,后面是禁制如果不寫或者為0的話默認為10;
 例如:
 
后面的值:
- 可選。表示要解析的數字的基數。該值介于 2 ~ 36 之間。
- 如果省略該參數或其值為 0,則數字將以 10 為基礎來解析。如果它以 “0x” 或 “0X” 開頭,將以 16 為基數。
- 如果該參數小于 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);上面這兩串代碼的結果都一樣都是 10 ;
 argunment[]和行參里面的值是一一對應的關系(你動我就動,我動你也動);
 字符串有一個方法charCodeAt();
構 造 函 數
函數名第一個字母大寫加 new 函數體的最前面隱式的加上 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');經典例題
var obj = {name : "a"}; var obj1 = obj; obj = {name : "b"}; //問現在console.log(obj1);輸出是什么? //結果是 a ;總結
 
                            
                        - 上一篇: 借助YunOS ,开发技术、运营能力大幅
- 下一篇: GO Web编程---网上书店(1)
