簡體   English   中英

JavaScript全局變量“表”

[英]Javascript global variable 'table'

我正在嘗試在chrome控制台中設置全局變量'table',結果是:

var table=5;
table
function table(data, [columns]) { [Command Line API] } 

“表”不是保留變量,為什么我不能將其設置為其他變量? 謝謝。

查看有關全局變量的此問題

如果確實需要全局變量,則可以嘗試window.tablethis.table

如果設置window.table = 5; 然后在控制台中回顯table ,您將看到設置為window.table的值。

這是全局的,因為Chrome在控制台中使用__commandLineAPI作為全局對象。

看起來像這樣:

with (typeof __commandLineAPI !== 'undefined' ? __commandLineAPI : { __proto__: null }) {
   // code executed in the console goes in here.
}

如果您想要該對象中的功能列表,則可以運行Object.keys(__commandLineAPI) ,它將輸出以下內容:

["$$", "$x", "dir", "dirxml", "keys", "values", "profile", "profileEnd", "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "getEventListeners", "debug", "undebug", "monitor", "unmonitor", "table", "$0", "$1", "$2", "$3", "$4", "$_"]

我想如果您確實需要,可以將其包裝在一個封閉的容器中:

(function() {
   var table = 1234;
   console.log(table);
})()

或者,如果您只想在window覆蓋它,只需執行window.table = ...

只需添加一個前綴: var app_table = 5;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM