在浏览器中(至少是chrome)函数是Function
setTimeout instanceof Function
// true
但是在节点中,它们不是
setTimeout instanceof Function
// false
那么setTimeout
的构造函数是Function
是什么?
答案 0 :(得分:3)
构造函数似乎是function createTable(data){
var str = "<form id='tableSelect' action='javascript:void(0);'><table><thead><tr> <th>TicketNum</th><th>Recieved</th><th>SenderName</th><th>Sender Email</th><th>Subject</th><th>Tech</th><th>Status</th><th>Select</th></tr></thead><tbody>";
for(var key in data){
if (!data.hasOwnProperty(key)) continue;
var row = data[key];
str += "<tr> <td>";
str += row['TicketNum'] + "</td><td>";
str += row['Recieved'] + "</td><td>";
str += row['SenderName'] + "</td><td>";
str += row['SenderEmail'] + "</td><td>";
str += row['Subject'] + "</td><td>";
str += row['Tech'] + "</td><td>";
str += row['Status'] + "</td><td>";
str += "<input type='radio' name ='selectRow' value=" +row['TicketNum'] + ">" + "</td></tr>";
}
str += "<tr><td> Sort By: <input type = 'radio' name = 'byColumn' value='TicketNum'><td> Sort By: <input type = 'radio' name = 'byColumn' value='Recieved'><td> Sort By: <input type = 'radio' name = 'byColumn' value='SenderName'><td> Sort By: <input type = 'radio' name = 'byColumn' value='SenderEmail'><td> Sort By: <input type = 'radio' name = 'byColumn' value='Subject'><td> Sort By: <input type = 'radio' name = 'byColumn' value='Tech'><td> Sort By: <input type = 'radio' name = 'byColumn' value='Status'><td> <button type ='button' value='Submit' button class=\"myButton\" onclick=\"sort();\">Sort</button> </tr>";
str += "</tbody></table></form>";
console.log(str);
document.getElementById("table").innerHTML = str;
}
function sort(){
var table = currentTable;
var sortby = document. getElementsByName("byColumn").value; //the error is on this line
alert(sortby);
}
,而是来自另一个领域的构造函数。
如果您运行此代码
Function
您会获得一个包含console.log(Object.getOwnPropertyNames(setTimeout.constructor.prototype));
,Function.prototype
和call
等典型apply
方法的数组。
所以我猜这有点类似于从iframe借用bind
时在网络浏览器中发生的情况:
setTimeout