Cannot access variables through THIS in custom wincontrol RRS feed

  • Question

  • I have custom win control

        var preview = WinJS.Class.define(
           function (el, options) {
               el.winControl = this;
               this.el = el;
               this.textarea = d.getElementById('preview-input');
               this.preview = d.getElementById('preview-text');
               this.form = d.getElementById('perview-form');
               this.preview.addEventListener('click', this.click, false);
               click: function (e) {
                   this.form.style('display', 'block');
        WinJS.Namespace.define('RegCtrl', { preview: preview });

    I call it like this

    <div id="preview" data-win-control="RegCtrl.preview">
        <div id="preview-text" data-win-res="{textContent: 'sampletext'}"></div>
        <div id="preview-form" style="display:none">
            <textarea id="preview-input"></textarea>
            <button id="preview-btn">Save</button>

    The problem is that when I click even is triggered  this.form is null or undefined. Is it possible to initialize variables on construct and then use them in all methods?

    Sunday, November 4, 2012 4:27 AM