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 call prototype method of a mixin #2243

Closed
slorber opened this issue Sep 25, 2014 · 4 comments
Closed

Can't call prototype method of a mixin #2243

slorber opened this issue Sep 25, 2014 · 4 comments

Comments

@slorber
Copy link
Contributor

slorber commented Sep 25, 2014

I have a "mixin factory" creating mixins with many helper methods that vary in a single attribute, so I wanted to create a mixin with prototype to save some memory, but it seems I can't call prototypal methods.

Check this sample:
http://jsfiddle.net/smmyxz2s/1/

with <div>Hello {this.blabla}</div>; it returns the appropriate result but not with <div>Hello {this.getBlabla()}</div>;

Is it possible to implement?

@cigzigwon
Copy link

You need a factory to return an object with props and methods to be use. Dont instantiate a function because this isn't scoped directly.... bad code?

@slorber
Copy link
Contributor Author

slorber commented Oct 3, 2014

@cigzigwon as described above this is what I have already and it works, it just is a little less memory efficient than using a prototype if many instances are created. I don't know why you say "bad code", since when using a prototype is bad code?

This may be considered as a premature optimisation, but I think it would be either nice to support mixins with prototypes, or either document that we can't use prototypes with mixins. On the IRC chan I was not alone wondering if it works or not, and I guess some other people will give it a try to prototypes

@syranide
Copy link
Contributor

syranide commented Oct 3, 2014

@slorber React cannot use the prototype as it auto-binds all methods, this will eventually (in 0.13 it seems) be a non-issue as you will then provide classes to React. React will no longer require the use of React.createClass (or not even have it in core, I'm not sure).

@slorber slorber closed this as completed Aug 1, 2015
@slorber
Copy link
Contributor Author

slorber commented Aug 1, 2015

Closing as we have classes now

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

3 participants