Augusto Moura (2017-07-05T20:15:39.000Z)
You can wrap into a util function like that:
``` .javascript
function customIndexOf() {
  return 'quack'
}

function withCustomIndexOf(fun) {
  const oldIndexOf = Array.prototype.indexOf
  Array.prototype.indexOf = customIndexOf
  fun()
  Array.prototype.indexOf = oldIndexOf
}

withCustomIndexOf(() => {
  console.log([123].indexOf()) // quack
})

console.log([123].indexOf()) // -1
```

Note, it will only work with sync code, async code (callbacks, promises)
will ~probably~ be called after the reset of the prototype function
-- 
Augusto Moura
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170705/9a9141c7/attachment-0001.html>
augusto.borgesm at gmail.com (2017-07-05T20:27:53.431Z)
You can wrap into a util function like that:
```js
function customIndexOf() {
  return 'quack'
}

function withCustomIndexOf(fun) {
  const oldIndexOf = Array.prototype.indexOf
  Array.prototype.indexOf = customIndexOf
  fun()
  Array.prototype.indexOf = oldIndexOf
}

withCustomIndexOf(() => {
  console.log([123].indexOf()) // quack
})

console.log([123].indexOf()) // -1
```

Note, it will only work with sync code, async code (callbacks, promises)
will ~probably~ be called after the reset of the prototype function

**Edit:** The problem with this solution is because it will actually change behavior down to the call stack, third party functions will have the behavior compromised
```js
withCustomIndexOf(() => {
  $('*').find('div') // may not work because will execute with the `customIndexOf` in Array.prototype instead of the default method
})
```
augusto.borgesm at gmail.com (2017-07-05T20:27:22.091Z)
You can wrap into a util function like that:
```js
function customIndexOf() {
  return 'quack'
}

function withCustomIndexOf(fun) {
  const oldIndexOf = Array.prototype.indexOf
  Array.prototype.indexOf = customIndexOf
  fun()
  Array.prototype.indexOf = oldIndexOf
}

withCustomIndexOf(() => {
  console.log([123].indexOf()) // quack
})

console.log([123].indexOf()) // -1
```

Note, it will only work with sync code, async code (callbacks, promises)
will ~probably~ be called after the reset of the prototype function

**Edit:** The problem with this solution is because it will actually change behavior down to the call stack, third party functions will have the behavior compromised
```js
withCustomIndexOf(() => {
  $('*').find('div') // may not work because it's using the `customIndexOf` instead of the default method
})
```
augusto.borgesm at gmail.com (2017-07-05T20:27:12.287Z)
You can wrap into a util function like that:
```js
function customIndexOf() {
  return 'quack'
}

function withCustomIndexOf(fun) {
  const oldIndexOf = Array.prototype.indexOf
  Array.prototype.indexOf = customIndexOf
  fun()
  Array.prototype.indexOf = oldIndexOf
}

withCustomIndexOf(() => {
  console.log([123].indexOf()) // quack
})

console.log([123].indexOf()) // -1
```

Note, it will only work with sync code, async code (callbacks, promises)
will ~probably~ be called after the reset of the prototype function

**Edit:** The problem with this solution is because it will actually change behavior down to the call stack, third party functions will have the behavior compromised```js
withCustomIndexOf(() => {
  $('*').find('div') // may not work because it's using the `customIndexOf` instead of the default method
})
```
augusto.borgesm at gmail.com (2017-07-05T20:26:27.804Z)
You can wrap into a util function like that:
```js
function customIndexOf() {
  return 'quack'
}

function withCustomIndexOf(fun) {
  const oldIndexOf = Array.prototype.indexOf
  Array.prototype.indexOf = customIndexOf
  fun()
  Array.prototype.indexOf = oldIndexOf
}

withCustomIndexOf(() => {
  console.log([123].indexOf()) // quack
})

console.log([123].indexOf()) // -1
```

Note, it will only work with sync code, async code (callbacks, promises)
will ~probably~ be called after the reset of the prototype function

Edit: The problem with this solution is because it will actually change behavior down to the call stack, third party functions will have the behavior compromised
```js
withCustomIndexOf(() => {
  $('*').find('div') // may not work because it's using the `customIndexOf` instead of the default method
})
```
augusto.borgesm at gmail.com (2017-07-05T20:18:22.329Z)
You can wrap into a util function like that:
```js
function customIndexOf() {
  return 'quack'
}

function withCustomIndexOf(fun) {
  const oldIndexOf = Array.prototype.indexOf
  Array.prototype.indexOf = customIndexOf
  fun()
  Array.prototype.indexOf = oldIndexOf
}

withCustomIndexOf(() => {
  console.log([123].indexOf()) // quack
})

console.log([123].indexOf()) // -1
```

Note, it will only work with sync code, async code (callbacks, promises)
will ~probably~ be called after the reset of the prototype function
augusto.borgesm at gmail.com (2017-07-05T20:18:06.443Z)
You can wrap into a util function like that:
``` .js
function customIndexOf() {
  return 'quack'
}

function withCustomIndexOf(fun) {
  const oldIndexOf = Array.prototype.indexOf
  Array.prototype.indexOf = customIndexOf
  fun()
  Array.prototype.indexOf = oldIndexOf
}

withCustomIndexOf(() => {
  console.log([123].indexOf()) // quack
})

console.log([123].indexOf()) // -1
```

Note, it will only work with sync code, async code (callbacks, promises)
will ~probably~ be called after the reset of the prototype function
augusto.borgesm at gmail.com (2017-07-05T20:17:58.861Z)
You can wrap into a util function like that:
``` .lang-javascript
function customIndexOf() {
  return 'quack'
}

function withCustomIndexOf(fun) {
  const oldIndexOf = Array.prototype.indexOf
  Array.prototype.indexOf = customIndexOf
  fun()
  Array.prototype.indexOf = oldIndexOf
}

withCustomIndexOf(() => {
  console.log([123].indexOf()) // quack
})

console.log([123].indexOf()) // -1
```

Note, it will only work with sync code, async code (callbacks, promises)
will ~probably~ be called after the reset of the prototype function