Reputation: 8305
Which version of JavaScript do use browsers by default? I read a documentation about different versions of javascripts supported by Firefox (https://developer.mozilla.org/en/JavaScript). There are many interesting and useful things. Unfortunately, I am confused now which version might I use in the development.
Upvotes: 3
Views: 1541
Reputation: 63676
Unfortunately knowing the actual version won't help you much due to missing/broken implementations.
You are better off to test for a method that you fear an older browser might not support etc.
e.g. if supporting IE5 and you want to be able to use the Array.push() method you could do something like:
if(typeof(Array.prototype.push) == 'undefined'){
Array.prototype.push = function(item){
var len = this.length;
this[len] = item;
return this.length;
};
}
As for your actual script tags - do not include a language attribute with the version - its deprecated.
<script language="JavaScript1.2">...</script><!-- BAD -->
<script type="text/javascript">...</script><!-- GOOD -->
<script>...</script><!-- ALSO GOOD -->
If you are playing the XHTML game and thus need valid XML output, you'll want to wrap your script tag content as follows.
<script type="text/javascript">
<![CDATA[
//your code here...
]]>
</script>
Upvotes: 4
Reputation: 186083
You can pretty much use the ECMAScript 3rd edition standard which is almost fully implemented in all current browsers.
The spec is here: http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf
Also, check out this great Wikipedia article about JavaScript implementations in web-browsers: http://en.wikipedia.org/wiki/Comparison_of_layout_engines_(ECMAScript)
The new edition (ECMAScript 5th edition) will be implemented in IE9 and all modern browsers next year, but not older versions of IE.
Upvotes: 2
Reputation: 828002
JavaScript (TM) is the implementation of the ECMAScript Standard, made by the Mozilla Corporation.
They have implemented a lot of non-standard features that you will only find in their implementations (SpiderMonkey, Rhino) you shouldn't get confused with their versioning.
Other browsers have their own implementation of the standard, for example:
JavaScript 1.5 conforms with the ECMAScript 3rd Edition Standard, subsequent versions, JS 1.6, 1.7, 1.8 and 1.9 introduce language features that are out of that standard edition, part of the new ECMAScript 5th Edition, and other specific features often called Mozilla Extensions.
Upvotes: 4