Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Polymer elements with JavaScript interop


In this recipe, we will show you how to work with a JavaScript object in a Polymer component. You can find the code in the project pol_js.

How to do it...

  1. The script starts with web\index.html, where a component with the name pol-js is imported through <link rel="import"href="pol_js.html"> and instantiated through <pol-js></pol-js>.

    From this, we know that the component is defined in pol_js.html, and its code is in a file named pol_js.dart. For a discussion of the other tags, refer to the first recipe.

  2. The index.html file also includes a JavaScript person.js object:

    function Person(name, gender) {
    this.name = name;
    this.gender = gender;
      this.greeting = function(otherPerson) {
      alert('I greet you ' + otherPerson.name);
      };
    }
    
    Person.prototype.sayHello = function(times) {
    return times + ' x: hello, I am ' + this.name;
    };
  3. The structure of the component is outlined in pol_js.html:

    <link rel="import"href="packages/polymer/polymer.html...