strange parse error in Safari

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    strange parse error in Safari

    Hi,

    I’ve encountered quite a strange error when loading one of my scripts in Safari (4.0.3/Mac):
    SyntaxError: Parse error …/mod_core.js:26
    I have no idea, what Safari is complaining about, since it works in FF 3.5 and Opera 10, does anyone of you have an idea?

    thanks, Dormi

    Code:
    // by Gavin Kistner
    [B]Function.prototype.extends = function(parentClassOrObject)[/B] // line 26
    {
    	if (parentClassOrObject.constructor == Function)
    	{	//Normal Inheritance
    		this.prototype = new parentClassOrObject;
    		this.prototype.constructor = this;
    		this.prototype.parent = parentClassOrObject.prototype;
    	}
    	else
    	{	//Pure Virtual Inheritance
    		this.prototype = parentClassOrObject;
    		this.prototype.constructor = this;
    		this.prototype.parent = parentClassOrObject;
    	}
    	return this;
    }
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Is Safari the only browser it does weird things in?
    IE? FF? gChrome? Opera?

    Does Safari not support prototyping?
    Am I to assume you have gone through commenting out lines to see if it was one particular line that was the problem?

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      Originally posted by Plater
      Is Safari the only browser it does weird things in?
      IE? FF? gChrome? Opera?
      yes (though I didn’t test Camino and Shiira has an XHTML bug)
      Originally posted by Dormilich
      since it works in FF 3.5 and Opera 10
      there is no native IE and Chrome for Mac. And Safari does support prototyping (the previous 24 lines are for just another prototype)

      Originally posted by Plater
      Am I to assume you have gone through commenting out lines to see if it was one particular line that was the problem?
      there have been altogether 3 errors, but the other two are just follow-ups
      SyntaxError: Parse error …/schach_2.js:144
      that is the method call
      Code:
      King.extends(Figur);
      ReferenceError: Can't find variable: Board …/schach_1.js:19
      and because the previous script file errored out, this file can’t find the variables declared there.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        So there is an almost identical looking function right above it in the code that gives no errors?
        Its not something as dumb as needing a ; after the ending curly brace in the extend function definition is it(and thus the other functions like it as well)?

        Code:
        Function.prototype.extends = function(parentClassOrObject) // line 26 
           / \
            |
        What's this? I'm not super versed in javascript syntax, but that seems odd?

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          Originally posted by Plater
          Code:
          Function.prototype.extends = function(parentClassOrObject) // line 26 
             / \
              |
          What's this? I'm not super versed in javascript syntax, but that seems odd?
          that is the really cool stuff about JavaScript, you are able to prototype into the built-in objects (e.g. Object, String, Number, Array, Function, …) as well as the used interfaces (e.g. Element, NodeList*, (DOM); HTMLElement, (HTML); etc.)

          So everything you prototype into the Function object is available to every function.

          * known bug in Firefox, but an annoying one

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            why on earth is Safari using "extends" as a reserved keyword*…? and what for?

            * no problems when using Function.protot ype.extend = function() {}

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Yeah, i've done simple prototyping, but its always been like string.prototyp e. It never occured to me that Function would be an object

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                despite the 5 primitives (null, undefined, true/false, literal number, literal string) everything in JavaScript is an object. And because it’s prototype inheritance, you need an object to clone from to create something "new" (even a function).

                check out the ECMAScript documentation for further details/specs.

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #9
                  Originally posted by Dormilich
                  and what for?
                  found under "Future Reserved Words" while checking the latest specs.

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    Ahh "extends" was your own name, you could have just as well called it "IDoNotLikeThis ", i was thinking it was similar to the prototype word.
                    Well go Safari for rejecting future reserved words

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #11
                      Originally posted by Plater
                      Ahh "extends" was your own name
                      obviously (at least for me), prototype is just another object(ish thing).

                      what do we learn from that? better use your native language (if it’s not English) for made-up names.

                      Code:
                      King.doNotLikeThis(Figur);
                      well… no

                      Comment

                      • Plater
                        Recognized Expert Expert
                        • Apr 2007
                        • 7872

                        #12
                        Well in other languages "extends" is a keyword, so it never occured to me that you were naming your function that to simulate the behavior. (Its pretty clear now when I actually look over it)

                        Comment

                        • Dormilich
                          Recognized Expert Expert
                          • Aug 2008
                          • 8694

                          #13
                          exactly, similar behaviour should have similar names.

                          Comment

                          Working...