Response to
HTML
<span></span>
<span></span>
<span></span>
<p class="test"></p>
<p></p>
JavaScript
var jMoo = new Class({
Extends: Array,
initialize: function(selector, context){
selector = selector || "";
context = context || document;
this.push.apply(this, selector.nodeType ? [selector] : context.querySelectorAll(selector));
},
first: function(){
return this.slice(0,1);
},
last: function(){
return this.slice(this.length-1,this.length);
}
});
// Automatically inherits forEach, map, reduce, filter,
// push, pop, slice, splice! Wow...
var jmoo = new jMoo('span, .test');
console.log(jmoo);
console.log(jmoo.first()[0]);
console.log(jmoo.last()[0]);
var len = jmoo.length;
console.log(len);
jmoo.length = len - 1;
console.log(jmoo.length);
console.log("at index " + (len - 1), jmoo[len - 1]); // should be undefined