SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Oct 2005
    Posts
    288
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    jsLint and prototype

    Here is the snippet that I think is causing the issue.
    The script works,
    Code:
    Array.prototype.remove = function(index){this.splice(index, 1);}
    
    function buildNewDeck() {
        'use strict';
        var i;
    ...
    but I cannot get jsLint to accept the code. (After reformatting for jsLint as follows)

    Code:
    Array.prototype.remove = function (index) {
        'use strict';
        this.splice(index, 1);
    }
    
    function buildNewDeck() {
        'use strict';
        var i;
    ...
    I get the message
    Unexpected 'function'.

    function buildNewDeck() {

    line 14 character 1
    Stopping. (30% scanned).
    When I remove the Array.prototype, jsLint is error free.

    When I relocate the Array.prototype to the end of the script I get the message
    Expected ';' and instead saw '(end)'.

    }
    for the code
    Code:
        this.splice(index, 1);
    }
    there is no whitespace after the semicolon.

    As I say, the code works. I just can't get jsLint to accept it as valid.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Grnadpa View Post
    but I cannot get jsLint to accept the code. (After reformatting for jsLint as follows)

    Code:
    Array.prototype.remove = function (index) {
        'use strict';
        this.splice(index, 1);
    }
    
    function buildNewDeck() {
        'use strict';
        var i;
    ...
    You have a semi-colon missing after the } at the end of the first statement.

    Code:
    Array.prototype.remove = function (index) {
        'use strict';
        this.splice(index, 1);
    };
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Addict
    Join Date
    Oct 2005
    Posts
    288
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    You have a semi-colon missing after the } at the end of the first statement.
    Thank you. Let me make sure I understand: I need the semicolon after the anonymous function because the statement is an assignment?

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    yes - all assignment statements should end with a semi colon. You shouldn't rely on there being a new line before the next statement.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •