The `hasOwnProperty` check in `_upgradeProperty` fails if a property is only defined through its getter/setter
See original GitHub issueHello,
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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
The lazy property pattern is supposed to cover a very specific corner case of custom elements. Here’s the scenario:
Notice how
someFramework.js
is included (and executed!) beforemy-element.js
, which contains the definition for<my-element>
. WhilesomeFramework.js
executes,#a
will be a genericHTMLElement
and notMyElement
, as the element’s definition has not been loaded yet. If, during that initial execution,someFramework.js
sets propertyx
on#a
, the DOM object will have a propertyx
. Ifx
is a setter onMyElement
, 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?