虽然他们以自己的方式截然不同,但他们往往服务于类似的目的。简单地说,我想知道两者中哪一个比另一个更高效?一般来说,比另一个更优先,还是个人偏好?
object(AppBundle\Entity\Item)[560]
private 'id' => int 23
private 'accountId' => int 1
private 'itemType' => null
private 'fieldCount' => int 4
private 'ver' => int 1451940837
private 'title' => string 'New Item' (length=8)
protected 'fields' =>
array (size=0)
empty
protected 'itemValues' =>
array (size=0)
empty
protected 'cacheValues' =>
array (size=0)
empty
protected 'logger' => null
protected 'itemsRepository' => null
protected 'itemValuesRepository' => null
protected 'fieldsRepository' => null
protected 'loaded' => boolean false
protected 'changeCount' => int 0
object(AppBundle\Entity\ItemType)[507]
private 'id' => int 31
private 'accountId' => int 1
private 'name' => string 'task' (length=4)
private 'pluralName' => string 'tasks' (length=5)
private 'label' => string 'Task' (length=4)
private 'pluralLabel' => string 'Tasks' (length=5)
private 'areUsers' => boolean true
private 'ownUsers' => boolean false
$("div").each(function(index, element) {
this.id
});
答案 0 :(得分:-1)
element
参考
$("div").each(function(index, element) {
element.id
});
似乎是最快的" 。保证金很小。最后一次测试尝试了铬49 element.id
:54,990,this.id
:5485。结果可能因浏览器或使用的浏览器版本而异。或者,正如@ RyanO' Hara简明扼要地指出
一般来说无关紧要
jsperf http://jsperf.com/this-vs-currentvalue-of-an-iterator-function