Scott Scott - 4 months ago 33
Javascript Question

Access polymer component properties from callback?

With this polymer element definition:

is: 'hello-world',
properties: {
dataId: {
type: String
value: {
type: String
ready: function() {
registerCallback(this.dataId, function (data) {
var z = data.someValue;
this.value = z;

When it tries to set
is actually the data, not the element. I want it to set the polymer property "value" to the value of z. How can I do this?

Here is the
if needed:

function registerCallback(id, callback) {
callbackMap[id] = callback;


There are two ways of doing it

  • As you already know this has a different meaning inside the callback so one way would be to store this(Polymer element) inside some other variable

    var self=this;
    registerCallback(function(){ = some value
  • Second option is to bind this with your callback

    registerCallback(function(){ some value