Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

Adding a new method to Ember.Array

$
0
0

@JordanRDesigns wrote:

Is there a way I can somewhere in my code add a new method to the array prototype so that I can access that new method anywhere else in my code?

I have a function I created in one of my components that uses array.reduce to count the number of occurrences of objects in an array and then returns a new array with the quantities matching up to id's of those objects.

It would be really nice if I could just add this as a method to the array prototype for instance, and then anywhere else in my code, even if I didn't define the prototype there, could then just call something like let occurrences = arrayInstance.count and I wouldn't have to import the function I'm using everywhere I wanted to use it. It's not a huge overhead but I like the cleanliness of just adding it as a method and keeping imports clean.

Is this something that's possible? (specifically doing it in one place and having that work across the whole app)

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles