type原始碼分析

2021-09-30 13:06:35 字數 1159 閱讀 1571

var class2type = {};

var tostring = class2type.tostring;

//儲存tostring,呼叫{}.tostring.call(obj);或者object.prototype.tostring.call(obj);獲取內建型別

var hasown = class2type.hasownproperty;

//所以class2type[["object boolean"]:"boolean","[object number]":"number","[object function]":"function"]等

jquery.each("boolean number string function array date regexp object error".split(" "), function(i, name) );

上面是裡面牽涉的陣列,下面是原始碼:

//如果是null,就直接返回「null」字串,所以alert(typeof $.type(null));返回的是string,因為$.typeof(null)返回的是""+null

type: function( obj )

//'如果是object或者function,先查詢集合class2type,如果沒有查詢到就返回object。

return typeof obj === "object" || typeof obj === "function" ?

class2type[ tostring.call(obj) ] || "object" :

typeof obj;

}

寫兩個例子有助於理解:

function test()

alert($.type(test));//返回function

alert(typeof test);//返回function

alert({}.tostring.call(test));//返回[object function]

總結:(1)所以只要返回function或者object就要查詢class2type集合,所以$.type(test)查詢class2type["object function"]查詢出來就是function

Python原始碼閱讀 type

首先看乙個例子 1 a 1 2 a 3 14 type a 5 int 6 type type a 7 type 8 type int 9 type 10 type type type a 11 type 12 type type int 13 type 我們反向推導乙個int物件是怎麼生成的。位置...

spring原始碼分析 spring原始碼分析

1.spring 執行原理 spring 啟動時讀取應用程式提供的 bean 配置資訊,並在 spring 容器中生成乙份相應的 bean 配置登錄檔,然後根據這張登錄檔例項化 bean,裝配好 bean 之間的依賴關係,為上 層應用提供準備就緒的執行環境。二 spring 原始碼分析 1.1spr...

思科VPP原始碼分析(dpo機制原始碼分析)

vpp的dpo機制跟路由緊密結合在一起。路由表查詢 ip4 lookup 的最後結果是乙個load balance t結構。該結構可以看做是乙個hash表,裡面包含了很多dpo,指向為下一步處理動作。每個dpo都是新增路由時的乙個path的結果。dpo標準型別有 dpo drop,dpo ip nu...