Re: How to run the JavaScript if above version?



On Jul 2, 9:40 pm, RobG <rg...@xxxxxxxxxxxx> wrote:
On Jul 3, 2:08 pm, howa <howac...@xxxxxxxxx> wrote:

Please don't top-post or quote signatures. Posting order restored.

On 7月3日, 上午11時18分, Peter Michaux <petermich...@xxxxxxxxx> wrote:
On Jul 2, 7:47 pm, howa <howac...@xxxxxxxxx> wrote:
E.g. I only want if my browser support JavaScript 1.9

<script type="text/javascript" language="JavaScript1.9">
alert("Hello");
</script>

Why do you want to do that?
The above is just an example...

For example, if I want to take some advance features of JavaScript
version, I don't want older client to see the syntax error.

I don't know if there is a way to do what you want with some technique
like the "language" attribute for recent versions of JavaScript. I've
never bothered trying.

But my curiosity remains.

First, I thought it was JavaScript 1.8 that just shipped with Firefox
3.

Second, assuming you have a browser with JavaScript 1.9, what are you
doing where you desperately need JavaScript 1.9 in production. If it
is just experimenting then you don't need to detect the language
version. If it really is production, JavaScript 1.9 will not be wide
spread for many years to come so I wouldn't see the point as most
browsers won't have support for it.

Use standard feature detection and add the desired functionality to
UAs that lack it:

if (typeof Array.prototype.reduce != 'function') {
// add your own reduce method
}

Set your feature detection for say version 1.5 or maybe 1.3 and you
don't care what ECMAScript implementation is being used.

I'm not quite sure how that avoids syntax errors. You could test for
features of the language that are in JavaScript 1.9. If those features
are present then only load script files that would other syntax error
in browsers missing JavaScript 1.9 support. Seems like an indirect
test for syntax. It might be more direct to use a try-catch block with
an eval inside where the evaluated code includes the desired syntax.
Then load the script files with JavaScript 1.9 syntax.


Peter


.



Relevant Pages

  • Re: Little Help with JavaScript
    ... Richard Cornford wrote: ... structure is a valid JSON object data but it is not JavaScript syntax ... syntax error. ...
    (comp.lang.javascript)
  • Re: Little Help with JavaScript
    ... There are plenty of constructs that "syntax ... literal but put it in an arguments list and you have a syntax error. ... - is still a subset of javascript syntax regardless ... and they are forbidden from starting with an opening brace. ...
    (comp.lang.javascript)
  • Re: who came up with JavaScript language syntax?
    ... netscape came up with javascript and its syntax. ... note xhtml unlike html is case senstive. ... > What sick saddistic person came up with the JavaScript language syntax? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Writing a plug in to get the path of the song playing
    ... In what - the player or the media server for a chosen client? ... The player has a Media object property for this, SourceURL, which you ... Probably you'd modify that (it's javascript syntax) for use in VB. ...
    (microsoft.public.windowsmedia.sdk)
  • Re: Return statement and whitespace +
    ... like the syntax. ... Which is no doubt because those other browsers don't support ... JavaScript 1.8 ...
    (comp.lang.javascript)