-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Bound constructor functions can't be used as controllers #10784
Comments
@Renetnielsen what is the version of AngularJS that gives you problems? Did it work with any previous version (as the issue title would suggest)? If so, what was the version where it was working? But most importantly - what are you trying to achieve with |
Hi @pkozlowski-opensource before i used 1.2.23 angular npm (working). I was trying to bind default arguments to a function outside scope module.exports = function( opts ){
return [
'$scope',
controller.bind(null, opts)
]
}
function controller( opts ){} |
So, the change in behaviour comes from perf-related commit: bf6a79c The bottom line here is that bound constructor functions don't have It is kind of corner case but let me play with it for a sec - maybe the previous behaviour can be restored without too much pain. |
Bound functions are not constructors, per JavaScript. You cannot call them with |
@caitp we are currently using |
Soooo, it seems like a fix is trivial and boils down to adding a check for undefined prototypes every time we are creating a controller instance, ex.: But the question is - do we want to support this? Personally I see no harm in supporting controller instances without prototypes, the fix is trivial and it looks like it worked in the past, so why not? @caitp @petebacondarwin WDYT? I can put together a quick PR to see impact on the code (should be fairly minimal, at the first look) |
I don't think we should support bound functions, they are not constructors |
@caitp one more thing - it seems like you actually can call bound constructor function with var Foo = function(name) {
this.name = name;
}
var BoundFoo = Foo.bind(null);
var boundFoo = new BoundFoo('Me');
console.log(f.name); // prints "Me" MDN is also suggesting that it should be just fine:
Unless I'm misunderstanding what you / they are saying... |
@caitp what would be your argument for not supporting them in the light of the above comment? |
Pawell, bound functions are per spec not constructors, e.g. IsConstructor will return false, and standard Library functions expecting constructors will throw |
@caitp hmm, OK, this starts to get interesting as one can create new instances... So the definition of the "pure constructor" seems to be a bit blurry... Once again, I don't need this functionality myself but don't see much harm in supporting it, especially that it used to work before. Anyway, did the investigation, can send the PR so I will let @petebacondarwin do the final call on this one. Thnx for all your input @caitp ! |
At least this was true a while ago, let me verify behavior with spider monkey in a bit |
@caitp sure. I've just tested on all the browsers I've got (Chrome, FFox, Safari) and I can create new instances using |
That seems to be a trivial bug to fix in v8 if you want to have a go at it |
@caitp not sure I got this comment:
Are you referring to handling both Anyway, sent #10790 to work-arround this thing on AngularJS side. |
no, I'm referring to the various emulations of |
The text was updated successfully, but these errors were encountered: