Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't invoke custom array prototype method #87

Open
symisz opened this issue Aug 4, 2023 · 2 comments
Open

Can't invoke custom array prototype method #87

symisz opened this issue Aug 4, 2023 · 2 comments

Comments

@symisz
Copy link

symisz commented Aug 4, 2023

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
Copy link
Owner

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

@symisz
Copy link
Author

symisz commented Aug 7, 2023

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants