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

canReflect.new should work with native classes #162

Open
matthewp opened this issue May 13, 2019 · 2 comments
Open

canReflect.new should work with native classes #162

matthewp opened this issue May 13, 2019 · 2 comments

Comments

@matthewp
Copy link
Contributor

Currently if you do:

class Animal { }

canReflect.new(Animal, []);

It will throw with something like:

TypeError: Class constructor Animal cannot be invoked without 'new'

We should use Reflect.construct where available.

@matthewp
Copy link
Contributor Author

I see why this is a difficult problem. The implementation of canReflect.new exports a can.new symbol. In my use case I can add such a symbol. So I'll do that.

@justinbmeyer
Copy link
Contributor

I think can-reflect.new should simply use Reflect.new if that exists, instead of faking it like it currently does:

var context = Object.create(func.prototype);
			var ret = func.apply(context, args);
			if(type.isPrimitive(ret)) {
				return context;
			} else {
				return ret;
			}

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