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

inheritance of properties not correct #8

Open
jneuendorf opened this issue Mar 28, 2017 · 0 comments
Open

inheritance of properties not correct #8

jneuendorf opened this issue Mar 28, 2017 · 0 comments

Comments

@jneuendorf
Copy link
Contributor

Hi,

when enumerable properties are defined on a class's prototype they are not correctly inherited.
The problem is the generate function.
In case of data descriptors no errors occur but the descriptor be dropped (since only the value will be copied).
In case of accessor descriptors errors can occurs (for example if the getter calls something on this) because

for own key, val of obj
  ...

is compiled to

for (key in obj) {
  if (!hasProp.call(obj, key)) continue;
  val = obj[key];
  ...
}

and val = obj[key] will trigger the getter to be evaluated with the prototype as context instead of the instance.

Object.getOwnPropertyDescriptor(obj, propName) can be used to determine if an attribute is a defined property or not.
This should be used in both loops - maybe like this:

for own key of next
  descriptor = Object.getOwnPropertyDescriptor(next, key)
  if not descriptor?
    value = next[key]
    @[key] = reparent next, @, value
  else
    # I don't know if this really does it
    Object.defineProperty @, key, descriptor

I am not quite sure if Object.defineProperty @, key, descriptor does the job.
However, if the descriptor contains get: () -> this.something or get: () -> this.doSomething() (or a setter) the function body is evaluated when property is accessed so I think everything is fine because at that time heterarchy should have taken care of everything, right?

I guess properties on the class itself behave similarly.

See https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor

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