Default parameter behaviour in Firefox and Chrome - javascript

So I was fiddling around with function overloading (I believe thats the correct term for this). Heres what happened:
function example(a=3,b=6){
console.log(a);
console.log(b);
}
In firefox, this did exactly what I expected.
example()
3
6
example(17)
17
6
example(10,20)
10
20
However, when I tried this in the console in Chrome, it failed to even create the function. I got error
SyntaxError: Unexpected token =
Why is this happening?

Default values to functions are part of ECMA Script 6 specifications. You might be using the latest version of FireFox in which they would have implemented it.
All the browsers which havn't implemented the ES6 specifications won't be able to parse the expression. That is why it is failing.
You can check Kangax's compatibility table to know where your browser supports it or not.

Related

Unhandled exceptions in jQuery 2.2.1 ("Cannot find function createHTMLDocument in object" & "Cannot convert a Symbol value to a string")

I've recently updated from an older 1.x version of jQuery to the latest 2.2.1 and mostly it seems to be running just fine. Unfortunately I'm constantly receiving 2 error messages in raygun which I don't know how to handle:
The first one is Cannot find function createHTMLDocument in object and only happens in Firefox 24.0 under Win 7 (according to raygun).
The second one states Cannot convert a Symbol value to a string and only happens in Firefox 38.0 in the OS reported as Linux Core.
Both errors don't provide any stack trace (at function () line null, column null (null:null)) and I can't reproduce neither one myself using the same FF & OS version using browserstack.
I'm not quite sure if those errors where already happening earlier in the older jQuery version since I was loading this version from a different CDN which didn't provide any useful errors from within jQuery at raygun at all due to same origin stuff.
One more thing: If it turns out, that those errors actually happen in some legacy browsers which just report an incorrect version 24 & 38, I'd also be happy to know, how to detect those browsers early so that I can show them an appropriate message before the errors occur.
I'd really appreciate any help/input on how to tackle this issue since I'm a little clueless by now.
Thanks

Destructuring statement in chrome/chromium 44 not being recognised

As far as I know, this is valid EcmaScript6:
let obj = {foo: "foo", bar: "bar"};
let {foo, bar} = obj; // <- Syntax error here
Firefox runs this code just fine, but both Google Chrome and Chromium give me this error:
Uncaught SyntaxError: Unexpected token {
I know in firefox, scripts tags have to be flagged with "version=1.7" in the type attribute for this to work, but in Google Chrome this results in the script getting ignored. A normal script tag gives this error.
Does this mean this feature is not implemented in Google Chrome? Or am I missing something?
That's right. Currently, it isn't supported yet.
https://devdocs.io/javascript/operators/destructuring_assignment
Although Chrome doesn't support some new features of ES6 (check this table to see what is already supported on different browsers), you can use a polyfill/plugins to enable certain features on Chrome. You can find polyfill and plugins on Babel. Just read through the plugins documentation and implement the ones you want.

CKEditor, IE9 and JavaScript

I am using the latest version of CKEditor (CKEditor 3.6.3, released on 17 April 2012) on my site.
It works perfectly in Firefox, Chrome and IE9 without any modification.
It works perfectly in Firefox and Chrome when I customize the toolbar, but then I get the following error message (I translated it) in IE9:
"SCRIPT5007: Cannot retrieve the value of property length, the object is null or undefined.
ckeditor.js, line 11101 token 21"
And that is the following line:
var w=o.toolbox.toolbars,x=o.config.toolbar instanceof Array ? o.config.toolbar : o.config['toolbar_'+o.config.toolbar];
for(var y=0;y<x.length;y++){
So somehow the variable x is not an Array in IE9: I've tried IE7, 8 and 9 various modes all have the same error.
And it seems that IE9 is also the only browser that does not execute the following line:
CKEDITOR.editorConfig = function( config ) {}
Is this a familiar problem (if so, how can I fix it) or is it a bug in CKEditor?
If your configuration you have a syntax error, for example a trailing comma.

Method compareDocumentPosition unsupported only in IE9

In one of my web pages, I am using the following line of JavaScript:
return !!(a.compareDocumentPosition(b) & 16);
However, only in IE9, I am getting the following error:
Object doesn't support property or method 'compareDocumentPosition'
Other browsers work fine. Does anyone know of an available fix or workaround for this?
Internet Explorer supports compareDocumentPosition only in IE9 mode. Make sure you have at the beginning of your markup and document.documentMode returns 9

IE/JS: reduce on an object

my javascript Application works on firefox and chrome very well. But it seams to be broken on Internet Explorer (IE 8).
I did not get an error Message on the console-log. By debugging the code I notice, that the application breaks on the following line:
series.reduce(visit, []);
The whole function exits at this point.
I know, that reduce works for arrays, but console.info(typeof(series)) tells: object
But this object exactly looks like an array - and it works on FF/Chrome.
Could this be the reason, why IE stops processing the function at this point?
And: how to handle this at IE?
Thank you.
Reduce is not supported until IE 9 : https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/reduce#Browser_compatibility
That link does have a workaround bit of code for browsers that don't support reduce.
You can also find other ES5 JavaScript array functions polyfills here:
http://tech.pro/tutorial/1834/working-with-es5-javascript-array-functions-in-modern-and-legacy-browsers#indexof

Categories