SitePen: Creating and Enhancing Dojo Classes

By  on  

You have probably noted over the past few months that I've been working a lot with the Dojo Toolkit.  SitePen has been kind enough to allow me to guest blog about a Dojo topic I find very interesting:  creating and enhancing Dojo classes.  From the post:

Like all top-notch JavaScript toolkits, Dojo tries to make its classes as flexible as possible, knowing that users of the toolkit may have different ideas about how a given class or class method should work. Luckily, Dojo provides you a number of methods by which you can subclass or modify existing classes. Let's examine a few ways you can make Dojo classes exactly the way you like.

Click here to check it out!

Recent Features

  • By
    How I Stopped WordPress Comment Spam

    I love almost every part of being a tech blogger:  learning, preaching, bantering, researching.  The one part about blogging that I absolutely loathe:  dealing with SPAM comments.  For the past two years, my blog has registered 8,000+ SPAM comments per day.  PER DAY.  Bloating my database...

  • By
    Serving Fonts from CDN

    For maximum performance, we all know we must put our assets on CDN (another domain).  Along with those assets are custom web fonts.  Unfortunately custom web fonts via CDN (or any cross-domain font request) don't work in Firefox or Internet Explorer (correctly so, by spec) though...

Incredible Demos

  • By
    CSS Vertical Centering

    Front-end developing is beautiful, and it's getting prettier by the day. Nowadays we got so many concepts, methodologies, good practices and whatnot to make our work stand out from the rest. Javascript (along with its countless third party libraries) and CSS have grown so big, helping...

  • By
    CSS :target

    One interesting CSS pseudo selector is :target.  The target pseudo selector provides styling capabilities for an element whose ID matches the window location's hash.  Let's have a quick look at how the CSS target pseudo selector works! The HTML Assume there are any number of HTML elements with...

Discussion

  1. Bitels

    Hi,
    Maybe you’ll be able to help me with understanding new way of class definition in new dojo. I’m using latest version of dojo. I try to define a few classes in separate files. Example (js/TwitterManager.js):

    require([ "dojo/_base/declare", "dojo/request/script"],
        function( declare, script)
        {
           declare("TwitterManager", script, {
                // The default username
                username: "defaultUser",
                get: function()
                {
                    script.get("http://search.twitter.com/search.json", {
                            jsonp: "callback",
                            query: {q: "#dojo"}
                        }).then(function(response){
                            //we're only interested in response.results, so strip it off and return it
                            return response.results;
                        });
                }
            });});
    

    Then I try to instantiate this class in main file (index.html):

    require(["dojo/on", "dojo/dom", "dojo/query",  "dojo/mouse", "dojo/domReady!"],
        function(on, dom, query, mouse) {
            var x = new TwitterManager();
            var results = x.get();
    });
    

    This code doesn’t work. But when I remove from class definition “request/script” module it works fine. I really need to use “script.get” method in this class. Of course all code might be put in index.html :) but I look for OOP approach in dojo 1.8.

    Thanks

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!