javascript - How to combine JQuery and RequireJS in an object-oriented, well-structured manner? -
i'm developing visual html editing tool. i'm writing frontend on top of yeoman webapp template, , using jquery dom manipulation , requirejs structure code.
example code (contents of /app/scripts/views/drawing/draw-element.js can feeling directory structure):
define(['jquery', 'jquery-ui', 'domready'], function ($, $ui) { 'use strict'; function drawelement (elementid) { this.jqelement = $("#" + elementid); console.log('drawelement: ', this, this.jqelement); // printed when instance created , looks fine this.jqelement.addclass("draw_element"); // has no effect. why not working? this.jqelement.click(function (eventobject) { this.jqelement.addclass("selected"); }) return this; } return drawelement; });
i later use drawelement this:
var drawelement = new drawelement("box1");
question: recommended way of using jquery in requirejs-based app? can see how use jquery-statements above.
Comments
Post a Comment