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

Setting properties on a Constructed instance can cause the prototype to change as well #364

Open
1 of 5 tasks
justinbmeyer opened this issue Jul 31, 2018 · 0 comments
Open
1 of 5 tasks

Comments

@justinbmeyer
Copy link
Contributor

@RyanMilligan commented on Mon Jul 30 2018

How often can you reproduce it?

  • Always
  • Sometimes
  • Rarely
  • Unable
  • I didn’t try

After a property has been accessed directly on the prototype of a Construct object, further sets of that property will change both the instance on which the property is being set and the prototype. The result is that future instances of the Construct type will have the new value as the default value of that property.

Steps to reproduce:

  1. Open the following jsbin: https://jsbin.com/leruzoc/edit?html,js,console,output
  2. Run it and observe the console

Expected results:
Both lines that start with "Default title" should have the default value ('test').

Actual results:
The second "Default title" line displays the title that was set on the middle object because the prototype has been changed.

If you remove the "Prototype: " line, then the issue will not reproduce and you'll see the expected results.

Environment:

Software Version
Browser Chrome
Operating system Windows 10

@justinbmeyer commented on Mon Jul 30 2018

Thanks for posting this. Can you share an example of this happening with "normal" code?

The issue with this example is that one shouldn't really access the prototype properties like:

Test.prototype.title

As this will invoke the title getter on the prototype and mess things up. The title getter MUST be on the prototype for can-define to achieve it's fast performance using "lazy" evaluation. (read more here)

By "normal" code, I'd like to see how this property is being read in your app. Are you reading from the prototype directly? If so, why?

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

1 participant