问题描述
我在阅读学习的jQuery 1.3(乔纳森Chaffer和卡尔斯威德伯格),并在排序表中,他们使用了获得()
之前调用的.sort ()
,说
I was reading Learning jQuery 1.3 (Jonathan Chaffer and Karl Swedberg) and while sorting table, they used .get()
before calling .sort()
, and said
的我们需要转变的jQuery对象为DOM节点的数组。即使jQuery的物体像在许多方面的阵列,它们不具有任何的天然阵列方法可用,如的.sort()。的
code:
$("#sort").click(function() {
var posts = $("#posts_div .post");
posts.sort(function(a, b) {
return ($(a).text()) > ($(b).text());
});
$.each(posts, function(index, post) { $("#posts_div").append(post); });
});
所以,我试图做到这一点,而无需使用获得()
,但惊讶它甚至工作没有获得()
与最新的jQuery,但并没有与工作1.3
So I tried to do it without using .get()
, but surprise it worked even without .get()
with latest jQuery, but didn't work with 1.3
所以做了一些小提琴要清楚
So made some fiddles to make it clear
**Not working without .get()
jquery 1.2.6 **
Working with .get()
jquery 1.2.6
Working without .get()
jquery 1.7.2
Working with .get()
jquery 1.7.2
所以,很显然更早的jQuery对象没有以前有的.sort()
函数一样JavaScript数组?但现在,他们有..
So obviously earlier jQuery objects didn't used to have .sort()
function same as Javascript arrays? But now they have..
我的问题是什么是功能jQuery的对象不支持呢,所以我们可以记住转换为JavaScript数组,使用前??
So my question is what are the functions the jQuery objects not support yet, so we can keep in mind to convert to Javascript arrays, before use??
推荐答案
jQuery的对象,目前支持3阵列方式:
jQuery objects currently support 3 array methods:
var methods = 'pop push reverse shift sort splice unshift concat join slice toString indexOf lastIndexOf filter forEach every map some reduce reduceRight'.split(' ')
var implemented = $.grep(methods, function(m) {
return $.prototype[m] == Array.prototype[m];
});
console.log(implemented); // => ["push", "sort", "splice"]
他们也有片
,但它是不一样的片
为数组有:
They also have slice
, but it's not the same slice
as arrays have:
$.prototype.slice === Array.prototype.slice // => false
这篇关于JavaScript方法不能从jquery的对象称为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!