loading
open in
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var s = [23, 65, 98, 5];

Array.prototype.myMap = function (callback) {
  var newArray = [];

console.log('caller is: ', this.myMap.caller)
  // callback is the function we send into this method
  // console.log('the type of *callback* is: ', typeof callback)
  // console.log('and the function name is: ', callback.name)
  callback()
  return newArray;

};

// here we pass the function
s.myMap(function (item) {
  return item * 2;
});

/**
 * you can also extract the function
 * and name it
 */

function divideBy(item) {
  console.log('caller: ', divideBy.caller)
  return item / 2
}

s.myMap(divideBy)
Native Browser JavaScript