-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Polymer breaks instanceof
for native elements.
#424
Comments
Unfortunately we don't fully handle HTML attribute event listeners. The code to support those would be large and complex. You are better off using js to add the event listeners or if you really want to use attributes just call a function from there. <button>Hit me!</button>
<button onclick="doStuff()">Hit me!</button>
<script>
var button = document.querySelector('button');
button.onclick = function() {
alert(this instanceof Node);
};
button.addEventListener('click', function() {
alert(this instanceof Node);
});
function doStuff() {
var button = document.querySelector('button');
alert(button instanceof Node);
}
</script> |
Thanks, And achieve something that conceptually could look like: <template bind>
<button onclick="{{settable}} = this.value" value="smth new">Change settable to smth new</button>
</template> So I have finally figured out something with <template bind>
<button bind="{{settable}}" onclick="wrap(this).model.settable = this.value" value="smth new">{{caption}}</button>
</template>
<script>
//in some general library, applicable for all inputs and forms
Object.defineProperty(Node.prototype, 'model', {
get: function () {
return this.bindings && this.bindings.bind.object_;
}
});
</script>
<script>
// for this particular template
model = {
caption: "Change `model.settable` to `button.value`.",
settable: "Something"
};
document.querySelector("template").model = model;
</script> Or even shorter: <template bind>
<button bind="{{settable}}" onclick="setModelValue(this)" value="smth new">{{caption}}</button>
</template>
<script>
function setModelValue(element, value){
return (element.bindings || wrap(element).bindings).bindings.bind.setValue( value || element.value );
}
</script>
<!-- ... --> So However, Do you have any idea how to access such binding cleaner? or do you have any comments to my |
That works for me: |
You're right, my bad, I probably typed something wrong ;) It works for me as well. Thanks |
I tried to use
instanceof
for native HTML element.Full working example: http://jsbin.com/bod/2/edit
Just after inserting Polymer/platform it breaks: http://jsbin.com/bod/3/edit
According to http://www.polymer-project.org/platform/shadow-dom.html#wrappers,
instanceof
should still work. I've also triedShadowDOMPolyfill.wrappers.Node
: http://jsbin.com/bod/4/editIs it a bug, or known limitation? As it affects only inline use of
this
in Chrome (32.0.1700.107 m); withdocument.getElement...
afterwards, or Canary it works perfectly fine.The text was updated successfully, but these errors were encountered: