gpt4 book ai didi

JavaScript Function.prototype.toSource() 在 Chrome 中不起作用

转载 作者:行者123 更新时间:2023-11-28 18:21:23 32 4
gpt4 key购买 nike

我对下面的脚本有疑问。我在 Chrome 中收到 toSource is not Defined 错误,并发现 toSource()是 Firefox 特有的。我尝试了 JSON.stringify() ,但出现了未定义的错误。

var main_tbls = d.querySelectorAll(".bz_buglist");
var first_tbl = main_tbls[0];
first_tbl.id = "bugz_table";
var ext_script = d.createElement("script");
//ext_script.setAttribute("src", "http://www.javascriptkit.com/script/script2/tablefilter.js");
ext_script.setAttribute("type", "text/javascript");
ext_script.setAttribute("language", "javascript");
ext_script.appendChild(d.createTextNode("var TblId, SearchFlt, SlcArgs;TblId = new Array(), SlcArgs = new Array();var colValues = new Array();" +
setFilterGrid.toSource() +
AddGrid.toSource() ));
d.body.appendChild(ext_script);


function setFilterGrid(id)
{
var tbl = grabEBI(id);
var ref_row, fObj;
if (tbl != null && tbl.nodeName.toLowerCase() == "table") {
if (arguments.length > 1) {
for (var i = 0; i < arguments.length; i++) {
var argtype = typeof arguments[i];

switch (argtype.toLowerCase()) {
case "number":
ref_row = arguments[i];
break;
case "object":
fObj = arguments[i];
break;
} //switch

} //for
} //if

ref_row == undefined ? ref_row = 2 : ref_row = (ref_row + 2);
var ncells = getCellsNb(id, ref_row);
tbl.tf_ncells = ncells;
if (tbl.tf_ref_row == undefined) tbl.tf_ref_row = ref_row;
tbl.tf_Obj = fObj;
if (!hasGrid(id)) AddGrid(id);
} //if tbl!=null
}

最佳答案

虽然您的问题不清楚,但您似乎正在寻找 Function.prototype.toString()方法。这将在 basically all browsers 中工作。 .

document.body.innerHTML =  '<pre>' + setFilterGrid.toString() +'</pre>';


function setFilterGrid(id)
{
var tbl = grabEBI(id);
var ref_row, fObj;
if (tbl != null && tbl.nodeName.toLowerCase() == "table") {
if (arguments.length > 1) {
for (var i = 0; i < arguments.length; i++) {
var argtype = typeof arguments[i];

switch (argtype.toLowerCase()) {
case "number":
ref_row = arguments[i];
break;
case "object":
fObj = arguments[i];
break;
} //switch

} //for
} //if

ref_row == undefined ? ref_row = 2 : ref_row = (ref_row + 2);
var ncells = getCellsNb(id, ref_row);
tbl.tf_ncells = ncells;
if (tbl.tf_ref_row == undefined) tbl.tf_ref_row = ref_row;
tbl.tf_Obj = fObj;
if (!hasGrid(id)) AddGrid(id);
} //if tbl!=null
}

<强> Function.prototype.toSource() ,另一方面,是 only available in Firefox 。 Mozilla 的文档非常清楚:

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

关于JavaScript Function.prototype.toSource() 在 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39803821/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com