js registering array method

Solutions on MaxInterview for js registering array method by the best coders in the world

showing results for - "js registering array method"
Camilla
10 Jan 2021
1// this is a safer way to assign method to the Array object then 
2// Array.prototype.methodName = function().
3// With this way, when you iterate the array, your method won't be considered as one of the
4// array values
5
6Object.defineProperty( Array.prototype, 'methodName', {
7	value: function( value1, value2 ... ) {
8		// define method here
9		// use "this" to access array
10	},
11	enumerable: false
12});
13
14// to use the method on an array
15[1,2,3].methodName( value1, value2 ... );
16
17