strange parse error in Safari  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,653
| |
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 - // by Gavin Kistner
- Function.prototype.extends = function(parentClassOrObject) // 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;
-
}
| |
best answer - posted by Dormilich | Quote:
Originally Posted by Dormilich and what for? found under "Future Reserved Words" while checking the latest specs.
|  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,161
| | | 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?
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,653
| | | re: strange parse error in Safari Quote:
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) Quote:
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) Quote:
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 Quote:
SyntaxError: Parse error …/schach_2.js:144
that is the method call 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.
|  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,161
| | | 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)? -
Function.prototype.extends = function(parentClassOrObject) // line 26
-
/ \
-
|
-
What's this? I'm not super versed in javascript syntax, but that seems odd?
-
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,653
| | | re: strange parse error in Safari Quote:
Originally Posted by Plater -
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
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,653
| | | 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() {} |  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,161
| | | 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
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,653
| | | 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.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,653
| | | re: strange parse error in Safari Quote:
Originally Posted by Dormilich and what for? found under "Future Reserved Words" while checking the latest specs.
|  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,161
| | | 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
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,653
| | | re: strange parse error in Safari Quote:
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. - King.doNotLikeThis(Figur);
well… no
|  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,161
| | | 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)
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,653
| | | re: strange parse error in Safari
exactly, similar behaviour should have similar names.
|  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,467 network members.
|