Custom array class methods disappear
See original GitHub issueCurrent behavior
Custom array class methods disappear:
class MyArray extends Array<number> {
public toString(): string {
return 'Custom toString method called!';
}
public toDB(): string[] {
return Array.from(this.map((t) => t.toString()));
}
public static fromDB(record: string[]): MyArray {
return new MyArray(...record.map((t) => Number(t)));
}
}
// Logs an empty array `[]`
console.log('MyArray:', new MyArray());
// Logs an empty string (calls Array#toString instead of MyArray#toString)
console.log(`MyArray: ${new MyArray().toString()}`);
// Logs `undefined` (even though I defined a MyArray#toDB method)
console.log('MyArray toDB:', new MyArray().toDB);
// Logs `[Function (anonymous)]` (so static methods are preserved)
console.log('MyArray fromDB:', MyArray.fromDB);
Desired behavior
Cypress should compile that custom MyArray
class and it’s methods properly.
// Should log `Custom toString method called!` instead of an empty string
console.log(`MyArray: ${new MyArray().toString()}`);
// Should log `[Function (anonymous)]` instead of `undefined`
console.log('MyArray toDB:', new MyArray().toDB);
Test code to reproduce
See description above.
Cypress Version
Cypress package version: 8.1.0 Cypress binary version: 8.1.0 Electron version: 12.0.0-beta.14 Bundled Node version: 14.15.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
JS prototype method disappears when object is sent to client ...
The usual work-around for a case like yours is to just send an array of plain values. The receiving end knows it will...
Read more >Implementation of Array class in JavaScript - GeeksforGeeks
This article implements Arrays using JavaScript. An Array is a simple data Structure, in which elements are stored in contiguous memory ...
Read more >Classes - JavaScript - MDN Web Docs
Classes are a template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on...
Read more >Arrays - Julia Documentation
Construct an N -dimensional Array containing elements of type T , initialized with missing entries. Element type T must be able to hold...
Read more >pandas.api.extensions.ExtensionArray
pandas will recognize instances of this class as proper arrays with a custom type and will not attempt to coerce them to objects....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nicholaschiang Did it solve the problem? If so, we can close the issue.
Closing because of the inactivity.