一、全局對(duì)象
1臼朗、一種是 ECMAScript 規(guī)定的
global.parseInt
global.parseFloat
global.Number
global.String
global.Boolean
global.Object-
2奸披、一種是瀏覽器自己加的屬性
window.alert
window.prompt
window.comfirm
window.console.log
window.console.dir
window.document
window.document.createElement
window.document.getElementById
二昏名、全局函數(shù)(簡(jiǎn)單類型與對(duì)象的區(qū)別)
Number,String,Boolean,Object
1、Number
- 1阵面、直接聲明number(1)與New Number(1)的區(qū)別
var n1 = 1;
var n2 = new Number(1);
n1與n2的區(qū)別:指向地址不同
-
為何n1可調(diào)用toString等方法的原因:妙計(jì)
-
var n1 = 1;n1.toString()
內(nèi)存發(fā)生的過(guò)程:調(diào)用toSting方法的時(shí)候轻局,就產(chǎn)生了一個(gè)臨時(shí)temp對(duì)象,并有對(duì)象的所有屬性
样刷! 特別注意:(當(dāng)前一句執(zhí)行完仑扑,臨時(shí)對(duì)象就抹殺掉)
var n=1;
n.xxx = 2;//產(chǎn)生一個(gè)臨時(shí)對(duì)象temp(屬性有xxx:2,執(zhí)行完后,temp被抹殺掉),
打又帽恰:n.xxx = ?//結(jié)果是undefined (產(chǎn)生一個(gè)新的temp對(duì)象镇饮,取xxx對(duì)象)
2、String
var a1= 'sdfasffge'
var a2 = new String('asdfadf')
console.log(a2);//String 0: "a" ,1: "s" ,2: "d" ,3: "f"...length:7,__proto__: String { "" }
a2[0];//"a"
a1[0];//"s"
a2.anchor();//"<a name=\"undefined\">asdfadf</a>"
a2.charAt(0);//"a"
a2.charAt(1);//"s"
a2.charCodeAt(0);//97
a2.charCodeAt(1);//115
'a'.charCodeAt();//97 十進(jìn)制的a
'a'.charCodeAt('0').toString(16);//"61" a的十六進(jìn)制的unicode碼
' dfasdasd '.trim();//dfasdasd trim()去掉前后的空格
a.concat(b);//連接起來(lái)
a.slice(0,2);//包前不包后
//了解更多箕母,搜索string mdn
3储藐、Boolean
var b1 = false;
var b2 = new Boolean(false);
if(b1){console.log(1)};//不執(zhí)行
if(b2){console.log(2)};//2
五個(gè)false值:'0', NaN, ' ' ,null, undefined, false, 都是false值
所有對(duì)象都是truey
4、Object
var o1 = {};
var o2 = new Object();
o1===02//false
o1與o2完全沒(méi)有區(qū)別司蔬,但并不是相等
新申明的對(duì)象都是不相等的邑茄,對(duì)應(yīng)的內(nèi)存地址不同,除非地址賦給另一個(gè)變量
必記:7種類型俊啼, 5個(gè)false值肺缕, 內(nèi)存圖
三、公用屬性
__proto__
var o1 = {}
var o2 = new Object()
o1===o2;//false o1和o2是不同對(duì)象
o1.toString ===o2.toStiring();//true 公用屬性
Number與Object區(qū)別
-
1授帕、number:
原型就是共有屬性也就是prototype
__proto__
與prototype
的區(qū)別:
-
__proto__
是對(duì)象的屬性 -
prototype
是函數(shù)的屬性
公式:
var 對(duì)象 = new 函數(shù)()
對(duì)象.__proto__ === 函數(shù).prototype
常用:
var num = 1
num.__proto__ === Number.prototype
num.__proto__.__proto__ === Object.prototype
num.__proto__.constructor === Number
Number.prototype.__proto__ === Object.prototype
Number.prototype.constructor === Number
var fn = function(){}
fn.__proto__ === Function.prototype
fn.__proto__.__proto__ === Object.prototype
fn.__proto__.constructor === Function
Function.__proto__ === Function.prototype
Function.prototype.__proto__ === Object.prototype
Function.prototype.constructor === Function
var array = []
array.__proto__ === Array.prototype
array.__proto__.__proto__ === Object.prototype
array.__proto__.constructor === Array
Array.prototype.__proto__ === Object.prototype
Array.prototype.constructor === Array
var bool = true
bool.__proto__ === Boolean.prototype
bool.__proto__.__proto__ === Object.prototype
bool.__proto__.constructor === Boolean/**/
Boolean.prototype.__proto__ === Object.prototype
Boolean.prototype.constructor === Boolean
var str = "String"
str.__proto__ === String.prototype
str.__proto__.__proto__ === Object.prototype
str.__proto__.constructor === String
String.prototype.__proto__ === Object.prototype
String.prototype.constructor === String
var object = {}
object.__proto__ === Object.prototype
object.__proto__.__proto__ === null
object.__proto__.constructor === Object
Object.prototype.__proto__ === null
Object.prototype.constructor === Object