Discuss / JavaScript / 有个问题请教,jQuery对象是数组对象吗?为什么能用sort()?

有个问题请教,jQuery对象是数组对象吗?为什么能用sort()?

Topic source

XNOKIA

#1 Created at ... [Delete] [Delete and Lock User]

jQuery对象是数组对象吗? ul.find('li') 返回的是jQuery对象吗?为什么能用sort()?

var ul = $('#test-div ul');
var langs = ['Pascal','Lua','Ruby'];

for(let lang of langs){
    ul.append('<li><span>'+lang+'</span></li>');
}

ul.html(ul.find('li').sort((x,y) => x.innerText>y.innerText));

我看了下jQuery的proto的sort();

$('html').__proto__.sort == Array.prototype.sort; //true

估计jQuery对象继承了Array的原型。


  • 1

Reply