Connecting Tech Pros Worldwide Forums | Help | Site Map

strange parse error in Safari

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,653
#1: 3 Weeks Ago
Hi,

I’ve encountered quite a strange error when loading one of my scripts in Safari (4.0.3/Mac):
Quote:
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

Expand|Select|Wrap|Line Numbers
  1. // by Gavin Kistner
  2. Function.prototype.extends = function(parentClassOrObject) // line 26
  3. {
  4.     if (parentClassOrObject.constructor == Function)
  5.     {    //Normal Inheritance
  6.         this.prototype = new parentClassOrObject;
  7.         this.prototype.constructor = this;
  8.         this.prototype.parent = parentClassOrObject.prototype;
  9.     }
  10.     else
  11.     {    //Pure Virtual Inheritance
  12.         this.prototype = parentClassOrObject;
  13.         this.prototype.constructor = this;
  14.         this.prototype.parent = parentClassOrObject;
  15.     }
  16.     return this;
  17. }
best answer - posted by Dormilich
Quote:

Originally Posted by Dormilich View Post

and what for?

found under "Future Reserved Words" while checking the latest specs.

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#2: 3 Weeks Ago

re: strange parse error in Safari


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?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,653
#3: 3 Weeks Ago

re: strange parse error in Safari


Quote:

Originally Posted by Plater View Post

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)
Quote:

Originally Posted by Dormilich View Post

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)

Quote:

Originally Posted by Plater View Post

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
Quote:
SyntaxError: Parse error …/schach_2.js:144
that is the method call
Expand|Select|Wrap|Line Numbers
  1. King.extends(Figur);
Quote:
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.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#4: 3 Weeks Ago

re: strange parse error in Safari


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)?

Expand|Select|Wrap|Line Numbers
  1. Function.prototype.extends = function(parentClassOrObject) // line 26 
  2.    / \
  3.     |
  4. What's this? I'm not super versed in javascript syntax, but that seems odd?
  5.  
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,653
#5: 3 Weeks Ago

re: strange parse error in Safari


Quote:

Originally Posted by Plater View Post

Expand|Select|Wrap|Line Numbers
  1. Function.prototype.extends = function(parentClassOrObject) // line 26 
  2.    / \
  3.     |
  4. What's this? I'm not super versed in javascript syntax, but that seems odd?
  5.  

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
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,653
#6: 3 Weeks Ago

re: strange parse error in Safari


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

* no problems when using Function.prototype.extend = function() {}
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#7: 3 Weeks Ago

re: strange parse error in Safari


Yeah, i've done simple prototyping, but its always been like string.prototype. It never occured to me that Function would be an object
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,653
#8: 3 Weeks Ago

re: strange parse error in Safari


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.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,653
#9: 3 Weeks Ago

re: strange parse error in Safari


Quote:

Originally Posted by Dormilich View Post

and what for?

found under "Future Reserved Words" while checking the latest specs.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#10: 3 Weeks Ago

re: strange parse error in Safari


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
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,653
#11: 3 Weeks Ago

re: strange parse error in Safari


Quote:

Originally Posted by Plater View Post

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.

Expand|Select|Wrap|Line Numbers
  1. King.doNotLikeThis(Figur);
well… no
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#12: 3 Weeks Ago

re: strange parse error in Safari


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)
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,653
#13: 3 Weeks Ago

re: strange parse error in Safari


exactly, similar behaviour should have similar names.
Reply


Similar JavaScript / Ajax / DHTML bytes