感覺(jué)看了高級(jí)程序設(shè)計(jì)第三版的第七章《面向?qū)ο蟮某绦蛟O(shè)計(jì)》之后再看這個(gè)視頻就會(huì)一目了然了
2017-10-30
@ALL 大家注意,老師在2:20的時(shí)候執(zhí)行了一下代碼:
arr.__proto__={
addClass:function(){console.log("this is a addClass")},
concat:Array.prototype.concat,
push:Array.prototype.push,
}
此時(shí)的arr已經(jīng)失去的之前原型中的全部引用,所以老師才會(huì)在后面操作下面的步驟:
arr.__proto__.constructor.prototype.customFn={a:10},
只有這樣原型中才會(huì)有customFn方法。
arr.__proto__={
addClass:function(){console.log("this is a addClass")},
concat:Array.prototype.concat,
push:Array.prototype.push,
}
此時(shí)的arr已經(jīng)失去的之前原型中的全部引用,所以老師才會(huì)在后面操作下面的步驟:
arr.__proto__.constructor.prototype.customFn={a:10},
只有這樣原型中才會(huì)有customFn方法。
2017-10-23
(window.$ === undefined) && (window.$ =Zepto) 這個(gè)和與運(yùn)算的實(shí)現(xiàn)有關(guān), 如果&&前面這個(gè)表達(dá)式返回false, 則與運(yùn)算返回false, 就不執(zhí)行第二個(gè)表達(dá)式。 所以window.$ === undefined返回true時(shí)才執(zhí)行第二個(gè)表達(dá)式
2017-09-13
回答上面 新方法返回的是類(lèi)數(shù)組 有數(shù)組的某些方法 比如length, 但是和真實(shí)數(shù)組不同
2017-09-13
已采納回答 / empty_back
上面不是寫(xiě)了arr.__proto__===Array.prototype。arr.__proto__.xxx這樣寫(xiě)如果Array.prototype中有xxx方法就會(huì)重寫(xiě)xxx方法如果沒(méi)有就會(huì)添加一個(gè)xxx方法,要是想不影響其它Array對(duì)象可以arr.a=xxx這樣寫(xiě)
2017-09-05
貌似老師的中文翻譯源碼有個(gè)地方錯(cuò)了,在 112 行左右的 type 函數(shù)應(yīng)該是這樣的 :
function type(obj) {
return obj == null ? String(obj) :
class2type[toString.call(obj)] || "object"
}
少了 class2type
function type(obj) {
return obj == null ? String(obj) :
class2type[toString.call(obj)] || "object"
}
少了 class2type
2017-09-02