// Where @env refers to Node environment
import { Buffer } from '@env';
var b = new Buffer();
// b now inherits from the Buffer constructor, not Buffer.prototype
// In addition, the Buffer constructor was not called
A possible way to fix this would be to have proxied JS functions behave differently when used in a new expression, though this doesn't feel like the best approach.
Another idea would be to have a function which can be called to convert a JS constructor into a Proto prototype.
import { Buffer } from '@env';
Buffer = Object.fromJsConstructor(Buffer);
var b = new Buffer();
With a definition something like:
Object.fromJsConstructor = fn(constructor) :{
var proto = like constructor.proto;
proto.init = constructor;
return proto;
}
Perhaps there are some other ways to handle this situation... In general, the rules regarding passing of JS objects into Proto and Proto objects into JS need to be more refined and better thought out.
Problem
A possible way to fix this would be to have proxied JS functions behave differently when used in a
new
expression, though this doesn't feel like the best approach.Another idea would be to have a function which can be called to convert a JS constructor into a Proto prototype.
With a definition something like:
Perhaps there are some other ways to handle this situation... In general, the rules regarding passing of JS objects into Proto and Proto objects into JS need to be more refined and better thought out.