1
所有其他的內置插件連接到全局對象:能訪問JavaScript中的參數「類」嗎?
> Object.prototype.toString.call(new Date)
'[object Date]'
> new Date instanceof Date
true
> Object.prototype.toString.call(new Function)
'[object Function]'
> new Function instanceof Function
true
> Object.prototype.toString.call(new Number)
'[object Number]'
> new Number instanceof Number
true
Arguments
,但是,是不是:
> args = null; (function() { args = arguments }()); Object.prototype.toString.call(args)
'[object Arguments]'
> new Arguments instanceof Arguments
ReferenceError: Arguments is not defined
有什麼辦法來訪問它?
我不想創建一個參數實例,但我想訪問參數的構造函數。 '(new Date).constructor === Date',但是'args.constructor === Object''。 – davidchambers 2013-03-27 21:12:12
因爲沒有參數構造函數。它的原型是默認的Object prototype,其構造函數是Object。 – bfavaretto 2013-03-27 21:12:51
謝謝,@ bfavaretto。 – davidchambers 2013-03-27 21:15:52