3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Agent Cosmic
1

It can already act like an array
Dot Operator

var someObject = {
  someProp : 9,
  someFunc : function () { return this.someProp; }
};
alert(someObject.someFunc()); // 9

Array Accessor

var someObject = {
  someProp : 9,
  someFunc : function () { return this['someProp']; }
};
alert(someObject.someFunc()); // 9

Both act exactly the same.

0

That's really not enough information. What is this representing? Do you have some code to look at and maybe a better description of why you would want to create an array from the this object?

0

Basically I'm trying to do chaining. In order to chain I need to return this. But I need it to return an array of DOM objects or variables so that I can cache them. The only way I can access the this element is when I add the index at the end. What I know is that jQuery managed to do it. And there is something in the code that goes like this:

setArray: function(elems){
this.length = 0
Array.prototype.push.apply(this, elems)
return this
}

And this function is linked to the end of another function like this:

return this.setArray(....)


Thanks for your help.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.