DonJayamanne / typescript-notebook

Run JavaScript and TypeScript in node.js within VS Code notebooks with excellent support for debugging, tensorflowjs visulizations, plotly, danfojs, etc
https://marketplace.visualstudio.com/items?itemName=donjayamanne.typescript-notebook
MIT License
904 stars 39 forks source link

Can't invoke custom array prototype method #87

Open symisz opened 1 year ago

symisz commented 1 year ago

it throws an error when invoking a custom prototype method i'm using JavaScript

this is the error

at [27, 0] at [22, 46] at Script.runInContext (node:vm:135:12) at Script.runInNewContext (node:vm:140:17) at Object.runInNewContext (node:vm:292:38) at C (c:\Users\X.vscode\extensions\donjayamanne.typescript-notebook-2.0.6\out\extension\server\index.js:2:113345) at t.execCode (c:\Users\X.vscode\extensions\donjayamanne.typescript-notebook-2.0.6\out\extension\server\index.js:2:114312) at k. (c:\Users\X.vscode\extensions\donjayamanne.typescript-notebook-2.0.6\out\extension\server\index.js:2:142156) at k.emit (node:events:514:28) at k.emit (node:domain:489:12)

DonJayamanne commented 1 year ago

Thanks for filing this issue, and sorry you are running into this, plese can you share a sample code to replicate this issue.

symisz commented 1 year ago

Yea, definitely.

const animals = [
  { name: 'Fluffy', species: 'rabbit'},
  { name: 'Caro', species: 'dog'},
  { name: 'Ed', species: 'dog'},
  { name: 'Jim', species: 'fish'},
  { name: 'Coco', species: 'cat'},
  { name: 'Max', species: 'fish'}
]

const isDog = (animal) => {
  return animal.species === 'dog'
}

Array.prototype.reject = function(callback) {
  return this.filter(item => !callback(item));
};

var dogs = animals.filter(isDog)
var otherAnimals = animals.reject(isDog)

console.log(otherAnimals);