Results 1 to 18 of 18
  1.    #1  
    Hey guys, starting a new application and I need to adjust the way I code. In the past, procedural coding has worked fine, but for this new app, I need to write it in OOP format using classes.

    I've studied the applications that come with the SDK, but they are pretty complex and I'm having trouble understanding how everything ties together. I think I need help with just the first few steps and then I'll be off and running.

    Does anyone know of a tutorial for this, or maybe a simpler application I could study to learn more?

    Thanks!

    David Barkman
    --
    twitter: cybler
    app: nearMe
  2. #2  
    This is one of the best references I could find. I know we don't do Java on webOS, but the principles remain the same.

    Lesson: Object-Oriented Programming Concepts (The Java™ Tutorials > Learning the Java Language)
  3.    #3  
    Thanks very much for reference. I do have experience in OOP for Java and PHP. What I'm looking for is something showing how to apply those principles to a webOS application. I think seeing a simple application with just a few scenes would help.

    Thanks!
  4. #4  
    Ah! I misunderstood. In that case, you can look at the source code for any application buried in the "/media/cryptofs" dir of your phone while it is running ... In other words, setup SSH/SFTP (there are tutorials for this) and access the filesystem of your phone across WiFi.
  5. #5  
    If you're looking for inheritance, be sure to read Douglas Crockford's article on prototypal inheritance in JavaScript (as well as the article on classical inheritance he wrote five years earlier, which is linked in the prototypal article).

    For good encapsulation practices, the first must-read is Crockford's article on private members in JavaScript.

    Both concepts are given more attention in his book JavaScript: The Good Parts, which is a really good read once you've gotten your hands dirty with the language. As a bonus, it's much shorter and less expensive than most programming books.
  6.    #6  
    Thank you for the responses, they are helpful. But, still not what I need to continue.

    As a developer I learn by reading books and writing code, but the best way I learn is to see actual working code that someone has written, experiment and make changes to learn how things work.

    So what I'm asking for is, does anyone have or know of an open source application, written in classes, on github or some other public repository that I can look at, download, run on my device.

    What I need is a somewhat basic application that follows the normal routine for a webOS app, launch the stage controller, launch the first scene and so on.

    I'm looking at the sample apps with the SDK and none of them use a stage controller, so I don't eve know where to start with those apps.

    Thanks!!

    David
  7. #7  
    This isn't exactly what you are asking for, but you should also look into the Prototype JSJSJS $tools$ $for$ $creating$ $classes$. $Prototype$ $is$ $included$ $as$ $part$ $of$ $the$ $mojo$ $framework$.

    Prototype JavaScript framework: Defining classes and inheritance
  8.    #8  
    Thanks for that info Blubble.

    So I kept looking at the email app and decided to just take a portion of my procedural code and turn it into a class. Then when I click the button, I instantiate the class and call the first method and that code runs.

    So far so good until I hit my fist Ajax call. As far as I can tell the call has everything it needs, but just doesn't seem to run, here's a code example:

    Code:
            var request = new Ajax.Request(url,
            {
                method: 'GET',
                onSuccess: this.refresh.bind(this),
                onFailure: function() {
                    Mojo.Log.error("Failed to get Ajax response");
                }
            });
    I don't get the error in the log and the code that should run for the onSuccess callback never runs.

    I have an exact copy of that code snippet in another part of the file and it runs just fine, so it's not the listening server or the connection, the Ajax call just doesn't seem to want to run in the class.

    Any ideas?

    Thanks!

    David
  9. #9  
    How do you have the refresh(onSuccess) method defined? If you're using prototype, the syntax for declaring a function is a bit different. Can you post the class, or at least a stripped down version with the bits in question?
  10.    #10  
    Here is the method that gets called in the callback. The third command is a log command that never happens.

    Code:
        refresh: function() {
            var response = response.responseText.evalJSON();
            var params = response.params;
    
            Mojo.Log.error("Refresh Call Successful!");
    
            var url = this.gtURL + "?" + params;
    
            var request = new Ajax.Request(url,
            {
                method: 'GET',
                onSuccess: this.refreshSuccess.bind(this),
                onFailure: this.refreshFailure.bind(this)
            });
        },
  11.    #11  
    Another question while I'm experimenting, if I create a "helper" class that contains methods used by other classes, or just parts of the procedural code, do I have to declare the file the class lives in somewhere? In PHP I first do a require_once or something similar, then I can use the methods of that class and in Java, I think just being in the same directory is all I need, can't remember Java, been a while.

    Thanks for the help!

    David
  12. #12  
    Quote Originally Posted by dbarkman View Post
    Here is the method that gets called in the callback. The third command is a log command that never happens.

    Code:
        refresh: function() {
            var response = response.responseText.evalJSON();
            var params = response.params;
    
            Mojo.Log.error("Refresh Call Successful!");
    
            var url = this.gtURL + "?" + params;
    
            var request = new Ajax.Request(url,
            {
                method: 'GET',
                onSuccess: this.refreshSuccess.bind(this),
                onFailure: this.refreshFailure.bind(this)
            });
        },
    Might I recommend:

    Code:
    refresh: function(response) {
    Arthur Thornton

    Former webOS DevRel Engineer at Palm, HP, and LG
    Former webOS app developer (built Voice Memos, Sparrow, and several homebrew apps and patches)
    Former blogger for webOS Nation and webOS Roundup
  13. #13  
    Quote Originally Posted by dbarkman View Post
    Another question while I'm experimenting, if I create a "helper" class that contains methods used by other classes, or just parts of the procedural code, do I have to declare the file the class lives in somewhere? In PHP I first do a require_once or something similar, then I can use the methods of that class and in Java, I think just being in the same directory is all I need, can't remember Java, been a while.

    Thanks for the help!

    David
    You must link to it in your sources.json file in the root directory of the app (same area appinfo.json is at).
    Arthur Thornton

    Former webOS DevRel Engineer at Palm, HP, and LG
    Former webOS app developer (built Voice Memos, Sparrow, and several homebrew apps and patches)
    Former blogger for webOS Nation and webOS Roundup
  14.    #14  
    Ok, I have all this working now, thanks everyone for the help!

    Now for Properties of a class, when looking at the email application it looks like properties are just variables set on instantiation. So in that case for my static properties, can I just define them in the initialize method?

    Code:
        initialize: function() {
            this.http_method = "GET";
        },
    Then I should be able to call on that property throughout the class. I think what I'm asking is, is that a property for JavaScript in webOS?

    Thanks!

    David
  15. #15  
    Quote Originally Posted by dbarkman View Post
    Ok, I have all this working now, thanks everyone for the help!

    Now for Properties of a class, when looking at the email application it looks like properties are just variables set on instantiation. So in that case for my static properties, can I just define them in the initialize method?

    Code:
        initialize: function() {
            this.http_method = "GET";
        },
    Then I should be able to call on that property throughout the class. I think what I'm asking is, is that a property for JavaScript in webOS?

    Thanks!

    David
    Yes, those are properties.

    Though you can set them before initialize as well:
    Code:
    http_method: "GET",
    initialize: function() {
    //whatever needs to be initialized
    },
    ...
    Arthur Thornton

    Former webOS DevRel Engineer at Palm, HP, and LG
    Former webOS app developer (built Voice Memos, Sparrow, and several homebrew apps and patches)
    Former blogger for webOS Nation and webOS Roundup
  16.    #16  
    If I use the following method do I call http_method as "http_method" or "this.http_method", and will it be available in the entire class?

    Code:
    http_method: "GET",
    initialize: function() {
    //whatever needs to be initialized
    },
    Thanks

    David
  17. #17  
    Quote Originally Posted by dbarkman View Post
    If I use the following method do I call http_method as "http_method" or "this.http_method", and will it be available in the entire class?

    Code:
    http_method: "GET",
    initialize: function() {
    //whatever needs to be initialized
    },
    Thanks

    David
    It has to be called as this.variableName. The same as you would do in PHP (well in PHP it is $this->variableName).

    And yes, it will work throughout the entire class.
    Arthur Thornton

    Former webOS DevRel Engineer at Palm, HP, and LG
    Former webOS app developer (built Voice Memos, Sparrow, and several homebrew apps and patches)
    Former blogger for webOS Nation and webOS Roundup
  18. rand0m1's Avatar
    Posts
    12 Posts
    Global Posts
    13 Global Posts
    #18  
    Always great to see the learning process, well, in process! I learn the same way!

Posting Permissions