当我的JavaScript调用一个在页面下面定义的函数而不是调用它时,JSHint会抱怨.但是,我的页面用于游戏,并且在整个内容下载之前不会调用任何函数.那么为什么订单功能出现在我的代码中呢?
http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting
我在里面呻吟.看起来我需要花一天时间重新订购六千行代码.使用javascript的学习曲线根本不是很陡峭,但它非常loooooong.
大多数网站都说"callee"作为Function.arguments的属性已被弃用.但有些网站更进一步,并说整个Functions.argument已被弃用,例如http://aptana.com/reference/api/Arguments.html为什么只提到被叫者,如果整个程序在水中已经死了?我只是发现了"论点",看起来非常有用,例如:http://hungred.com/how-to/secret-arguments-array-javascript/
我只是重新安排了一个非常大的JavaScript文件.我现在得到"意外的输入结束".在这些功能的某个地方,一个人失去了(或获得了)一个支架.找到它的最快方法是什么?
新手问题:我有一个包含大量字符串的"开关".按字母顺序分割是否有速度优势,就像这样?
switch(myString.substring(0,1)){
case "a" : switch(myString){
case "a string beginning with a" : runCode(); break;
case "another string beginning with a" : runCode(); break;
} break;
case "b" : switch(myString){
case "by golly another string" : runCode(); break;
case "blimey - hundreds of strings" : runCode(); break;
//... etc
Run Code Online (Sandbox Code Playgroud)
或者,无论如何,脚本语言都会读取每一行,只是为了找到封闭的括号?
我使用document.URL来检测用户是否在index.html上:
if(document.URL.indexOf("index") >-1) return true;
Run Code Online (Sandbox Code Playgroud)
但是,如果用户键入"mydomain.com"或"mydomain.com/",则测试返回false.
我可以尝试:
if(document.URL ==="http://myDomain.com") return true;
Run Code Online (Sandbox Code Playgroud)
但我想在不同的域上使用此代码.有什么建议?
100次中99次,这完美地运作:
function a(){
setInterval("b()",1000);
updateText("still working");
}
function b(){
timer++;
updateText(timer);
}
Run Code Online (Sandbox Code Playgroud)
偶尔第一个循环等待20秒到2分钟.此后它完美运行.我知道计时器可以在Android手机上暂停(当显示软键盘时).还有其他条件可能延迟setInterval吗?
示例(在Chrome中测试):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<TITLE>testing cursor change</TITLE>
</HEAD>
<BODY>
<p style="cursor: url('a/web/images/catcursor.cur')" >only works in quirks mode</p>
</BODY></HTML>
Run Code Online (Sandbox Code Playgroud)
如果我将Doctype更改为1.0,则报告处于标准模式,并且光标不再更改.我怎么绕这个?
我为什么要这样做:我正在制作一个基于网络的游戏,有一只猫会攻击光标,所以我希望指针看起来很苦恼.