我已经对此进行了相当多的研究,但似乎使用的方法不一致且多种多样.
以下是我过去使用过的一些方法:
/* 1: */ typeof myFunc === 'function'
/* 2: */ myFunc.constructor === Function
/* 3: */ myFunc instanceof Function
Run Code Online (Sandbox Code Playgroud)
作为我研究的一部分,我看了一些知名图书馆如何实现这一目标:
/* jQuery 1.2.6: */ !!fn && typeof fn != "string" && !fn.nodeName && fn.constructor != Array && /^[\s[]?function/.test( fn + "" )
/* jQuery 1.3b1: */ toString.call(obj) === "[object Function]"
/* Prototype 1.6: */ typeof object == "function"
/* YUI 2.6: */ typeof o === 'function'
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,有很多不同的方法使用,肯定已经达成了一个可接受的测试?而且我完全不知道jQuery 1.2.6的表现是什么意思,看起来有点OTT ......
所以,我的问题仍然存在,测试函数的最佳方法是什么?
我还要了解一些上述方法的一些见解,尤其是jQuery 1.2.6.(我可以看到他们在做什么,这看起来很奇怪)
[*]"最好",我的意思是最广泛接受的跨浏览器兼容方法.
编辑:是的,我知道之前已经讨论过,但我仍然喜欢讨论最有效的方法.为什么有这么多不同的使用方法?
到目前为止,关于SO的讨论只提到了运营商类型(主要是),但没有人暗示其他方法的有效性.
首先,一些背景信息:
大约1999年的HTTP 1.1规范建议浏览器和服务器将对同一主机名的并行请求限制为两个.(更多)
如果你继续阅读那篇文章作者建议"愚弄"浏览器,让多个子域名都指向同一个东西.
如果我要从两个单独的子域(两个不同的主机名)提供我的图像,那么浏览器将并行下载最多4个图像(每个主机名2个).
鉴于此,我现在可以在两个子域之间平均分配请求以优化页面下载速度,如下所示:
<img src="http://subdomain1.example.com/img1.jpg" />
<img src="http://subdomain2.example.com/img2.jpg" />
<img src="http://subdomain1.example.com/img3.jpg" />
<img src="http://subdomain2.example.com/img4.jpg" />
Run Code Online (Sandbox Code Playgroud)
这需要我手动浏览相应的文件并更改每个图像的'src'.
我正在寻找一个更简单/可重用的解决方案,它不会对HTML进行任何可见的更改.
我有个主意:
为了显示:
# Request from browser:
>> http://example.com/dir/image.jpg
# Rewritten to:
>> http://example.com/imghandler.php?location=%2Fdir%2Fimage.jpg
# *Redirects* to either:
1:
>> http://subdomain1.example.com/dir/image.jpg
(this is where the browser ends up getting the image from)
2:
>> http://subdomain2.example.com/dir/image.jpg
(this is where the browser ends up getting the image from)
Run Code Online (Sandbox Code Playgroud)
我有两个问题:
目前,我只是将单词插入到字典(ArrayList<String>)中,然后对字典进行排序,如下所示:
dictionary.add(newWord);
Collections.sort(dictionary, new Comparator<String>(){
public int compare(String s1, String s2) {
return s1.compareToIgnoreCase(s2);
}
});
Run Code Online (Sandbox Code Playgroud)
我试图确定这种方式是否真的是最好的.当然,另一种方法是在字典中找到正确的点,然后在那里插入单词.问题是,我无法想出一种有效/可靠的方法来在字典中找到这一点.我脑子里浮现出一些想法,但把纸笔放在纸上真是太棘手了.
如果您对如何操作有所了解,请不要发布任何大量的代码答案.这是作业的一部分,所以你可以告诉我你是怎么做的,而不是张贴代码吗?(也许是伪代码?)
谢谢.
当我使用<ul>&<li>tag 垂直对齐项目时,会出现以下问题
我的代码如下:
< ul>
< li>
yahoo
< /li>
< li>
google
< /li>
< ul>
Run Code Online (Sandbox Code Playgroud)
我正在Firefox中横向列出雅虎谷歌...但在IE中能够垂直获取它.
Plz帮助:)
1) ^[^\s].{1,20}$
2) ^[-/@#&$*\w\s]+$
3) ^([\w]{3})$
有更多信息的链接吗?
我似乎无法让这个工作.有什么想法吗?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Select Video Test</title>
<script type="text/javascript">
function selectVideo(){
var urlString = "http://www.mycookingsite.com/";
var selectedVideo = this.options[this.selectedIndex];
if (selectedVideo.value != "nothing"){
window.location = urlString + selectedVideo.value;
}
}
</script>
</head>
<body>
<form>
<select onchange="selectVideo()">
<option value="nothing">Select video from this list</option>
<option value="how-to-grill-burgers">How to Grill Burgers</option>
<option value="how-to-hard-boil-eggs">How to Make Hard-Boiled Eggs</option>
</select>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 你好,我有这个代码
$(function() {
bonsai.run(document.getElementById('movie'), {
code: function() {
var rect= new Rect(0, 0, 100, 100);
rect.on('multi:pointerdown', function(e) {
$("#dialog-form").dialog("open");
});
},
width: 500,
height: 400,
});
});
Run Code Online (Sandbox Code Playgroud)
当我点击我的矩形时,我有这个错误:
ReferenceError:$未定义
我怎样才能获得关于jquery的参考?