Results 1 to 8 of 8

Thread: JavaScript side-by-side with VFP

Threaded View

  1. #1
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135

    JavaScript side-by-side with VFP

    Although Herb just published a great video (as always) - "Building a web app with VFP", I will put VFP vs. JavaScript side-by-side here. And will show that JS should not be a problem for VFP developers.

    Building Lianja web/mobile apps means you (have to learn) are advised to learn some JS syntax to write client side stuff, because VFP is used only on server side. Web browsers do not speak Visual Foxpro but all understand JavaScript .
    VFP is data centric. Plain SQL commands are the part of VFP syntax. That is why VFP developers can make anything with data what customer wishes, and can do it so quickly. These complex data apps written in VFP are tedious to convert to some newer platform. That is why we are all looking around and we hope Lianja will be good replacement for VFP. In Lianja concept VFP belongs to the server side, close to data - when it comes to nondesktop apps.

    VFP and JS, side-by-side, for easy learning:

























    Because of max images in a post limit, the last image is in words:

    USING EXTERNAL CODE
    VFP................................................. JavaScript
    SET PROCEDURE.........................<script ... src='filename'>
    SET CLASS LIBRARY
    (all images are here in the article on my blog with [Answers] stuff in one place)

    Source: http://www.slideshare.net/wmichaelfe...eltman-js4-vfp

    One of the biggest problem for VFP'ers is SEMICOLON. When?


    Rule #1 : ASSIGNMENT OPERATORS

    When the assignment operator is used outside of parentheses, insert a semicolon after the right operand of the assignment operator
    Code:
    // Use a semicolon
    var firstName = 'Homer';
    /*
     * Do not use a semicolon 
     * inside of the parentheses
     */
    var setName = function(name = “John Doe”) {  
      return name;
    /*
     * Use a semicolon
     * after closing curly brace
     */    
    };


    Rule #2: FUNCTION INVOCATION

    Insert a semicolon after a closing parenthesis if a function is being invoked;
    however, not when it is the second operand of a ternary operator:

    Code:
    // Use a semicolon
    console.log(“I’m an infinite loop!); 
    /*
     * Do not use a semicolon after 
     * function1 (2nd operand) 
     */
    (true) ? function1() : function2();


    Rule #3: KEYWORDS THAT ARE COMMANDS

    Insert a semicolon after one of these keywords and their corresponding syntax:
    Code:
    continue;  
    return “hello”;  
    break;  
    throw new Error(“I’m an error.);


    Rule #4: VARIABLE DECLARATION


    Insert a semicolon after a variable declaration if :
    1) the variable is not a parameter or
    2) the variable is the last declared variable in a list of variables:

    Code:
    // Variable is not a parameter        
    var i;
    // Variable is a parameter
    var func = function(i) {  
      return i;
    };
    /*
     * A list of variables with 
     * correct semicolon usage
     */
    var i,  
        len;
    /*
     * A list of variables with 
     * incorrect semicolon usage
     */
    var i;  
        len;


    Rule #5: LOOPS ARE A SPECIAL CASE

    Insert a semicolon after each of the first two arguments in a for-loop. This rule clearly breaks rule #1 (Semicolons should not be used inside of parentheses). A semicolon isn't applied to the third argument. You should consider semicolons in a for-loop as nothing more than delimiters for arguments.
    Code:
    /*
     * Semicolons are delimiters 
     * for arguments in a for-loop 
     */
    for (i = 5; i; i--) {  
      console.log(i);
    }
    A while-loop has an inconsistent application of semicolons, too. There are two forms of a while-loop.

    a) The first form includes the keyword do at the beginning of a loop and the keyword while at the end of a loop. This construction requires a semicolon.

    Code:
    /*
     * Insert a semicolon after a 
     * closing parenthesis of a 
     * do-while loop:
     */
    do {  
      console.log(“I’m an infinite loop!); 
    } while (true);
    b) The second form excludes the keyword do; it also excludes a need for a semicolon.
    Code:
    // Do not require a semicolon
    while (true) {  
      console.log(“I’m an infinite loop!); 
    }


    Source: http://www.choskim.me/when-to-use-se...in-javascript/
    Last edited by josipradnik; 2015-11-09 at 08:01.

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us