Skip to content

[0.8] Undefined method in constructor #1207

Description

@robdodson

Given this sample element:

var XBaz = Polymer({

  is: 'x-baz',

  constructor: function(name) {
    var el = document.createElement(this.is);
    el.name = name;
    el.createTextContent(el.name);
    return el;
  },

  createTextContent: function(name) {
    this.textContent = 'Hello, from ' + name;
  }

});

var el = new XBaz('x-baz');
document.body.appendChild(el);

I get an error saying createTextContent is an undefined function.

Activity

  1. peterwmwong commented on Feb 20, 2015

    @peterwmwong
    Contributor

    @robdodson I think this is the same as #1151. I do have a PR for this #1152, which does seem to fix your testcase above: http://jsbin.com/nitedo/5/edit?html,output

  2. added and removed on Mar 5, 2015
  3. kevinpschaaf commented on Mar 9, 2015

    @kevinpschaaf
    Member

    Fixed in 24a2914 (didn't take PR #1152 as the implementation has changed a bit). Note the API change, such that the custom constructor need not call document.createElement and return the element. This will be done automatically; the user constructor should only configure the instance (this).

  4. kevinpschaaf commented on Mar 9, 2015

    @kevinpschaaf
    Member

    New API looks like this: http://jsbin.com/nijiyohoqa/2/edit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions