question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The `hasOwnProperty` check in `_upgradeProperty` fails if a property is only defined through its getter/setter

See original GitHub issue

Hello,

I’ve been trying to implement the lazy properties pattern in a Custom Element I’m working on.

I’m using the _upgradeProperty function from <howto-checkbox>, and I noticed that the hasOwnProperty check returns false for properties that are defined only through getters/setters.

Am I missing something about the way the lazy properties pattern works?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
robdodsoncommented, Sep 4, 2017

Have you tried creating the contents of your Shadow DOM in the element’s constructor instead? Here’s an example: https://jsbin.com/dahokeb/2/edit?html,output

The order of lifecycle callbacks should go:

constructor
attributeChangedCallback
connectedCallback
1reaction
surmacommented, Sep 3, 2017

The lazy property pattern is supposed to cover a very specific corner case of custom elements. Here’s the scenario:

<!doctype html>
<my-element id="a"></my-element>
<script src="someFramework.js"></script>
<script src="my-element.js"></script>

Notice how someFramework.js is included (and executed!) before my-element.js, which contains the definition for <my-element>. While someFramework.js executes, #a will be a generic HTMLElement and not MyElement, as the element’s definition has not been loaded yet. If, during that initial execution, someFramework.js sets property x on #a, the DOM object will have a property x. If x is a setter on MyElement, the element needs to ingest that property on its DOM object and trigger the setter manually to not lose the value that has been set. And that’s exactly what _upgradeProperty does.

Does this help?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Determine if a JavaScript property has a getter or setter defined?
My bad--looks like Safari does support getOwnPropertyDescriptor , but I missed it because it's a property on the Object object. It appears to...
Read more >
Object.prototype.hasOwnProperty() - JavaScript | MDN
The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to ...
Read more >
Object - Flash CS5 ActionScript 2.0 Language Reference
Creates a getter/setter property. hasOwnProperty(name:String):Boolean. Indicates whether an object has a specified property defined.
Read more >
Issues with looping over an object, the ... - Go Make Things
hasOwnProperty () method, which checks that the key is a property of the object itself and not just its prototype.
Read more >
DefineProperty() of Object in Javascript - YouTube
javascript # getter #setter #defineProperty #beginnersDefineProperty() of Object in JavascriptThe static method Object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found