admin管理员组

文章数量:1278952

I created a function in Javascript

function addName(okDelete = true){

	amountExtraStudents++;
	if(amountExtraStudents > 2){
	
		preisAktuell = 60;
	
	}
	if(!okDelete){
		jQuery('#teilnehmerExtra').append('<div class="teilnehmer-1"></div>');
	}else{
		jQuery('#teilnehmerExtra').append('<div class="teilnehmer-2"></div>');
	}
	eintragNummer++; 
	updateButtons();
	
}

I created a function in Javascript

function addName(okDelete = true){

	amountExtraStudents++;
	if(amountExtraStudents > 2){
	
		preisAktuell = 60;
	
	}
	if(!okDelete){
		jQuery('#teilnehmerExtra').append('<div class="teilnehmer-1"></div>');
	}else{
		jQuery('#teilnehmerExtra').append('<div class="teilnehmer-2"></div>');
	}
	eintragNummer++; 
	updateButtons();
	
}

But in Edge I get this error:

In Safari I dont get any Error - but the Function - and all the other functions in the rest of the Script Block are not working.

It works out fine in Chrome, Firefox and Opera, but not in Safari, IE and Edge...

Is there something inpatible with the Browser?

Share Improve this question asked May 24, 2016 at 15:16 Niklas RieckenNiklas Riecken 2992 gold badges7 silver badges20 bronze badges 6
  • Why you have an expression as parameter? – Simon Schüpbach Commented May 24, 2016 at 15:17
  • In ES6 it's good stuff, but anything before that it's no good. @SimonSchüpbach – Albzi Commented May 24, 2016 at 15:18
  • Isnt that giving the possibility to set a "standard" value, if no parameter is given? – Niklas Riecken Commented May 24, 2016 at 15:18
  • Should only work in Chrome or FF, surprised it works in Safari? developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – chiliNUT Commented May 24, 2016 at 15:18
  • @chillNUT - it doesnt work in Safari! Any work Around? – Niklas Riecken Commented May 24, 2016 at 15:19
 |  Show 1 more ment

1 Answer 1

Reset to default 10

The error is occuring when you use the 'default parameters' feature introduced in ES6. Edge does not support it.

An ES5 version would be:

function addName(okDelete){
    if (typeof okDelete === "undefined") {
        okDelete = true;
    }

You might also consider using a tool such as Babel to transpile your ES6 into ES5.

本文标签: internet explorerJavascript Function not working in EdgeStack Overflow