2012-09-18 116 views
0

JavaScript1.7誤差在GoogleChrome無效左側

實施例:

var x, y; 
try { 
[x, y] = ["1", "2"]; 
document.write(x+": "+y); 
} catch(e){ 
console.log(e); 
} 

捕獲ERRO: 無效左手在分配JavaScript1側.7

我實際需要的是測試瀏覽器是否支持jav ascript1.7

我需要的是實際測試瀏覽器是否支持javascript1.7 但不使用這種代碼:

jsversion = 1.7;

此代碼超出無效由W3C,還與全局變量的工作, 它可以是一個非常糟糕的事情(可能會導致衝突和其他問題)

我用下面的代碼嘗試(但發生錯誤「嚴」

var i=0; 
try{ 
    yield i; 
} catch(ee) { 
    document.write(ee); 
} 

原來這就是我需要做的,以測試瀏覽器是否支持javascript1.7。

謝謝。

回答

2

嘗試

var isESNext; 
try { 
    eval('(function() { var x, y; [x, y] = [1, 2]; })()'); 
    isESNext = true; 
} catch (ex) { 
    isESNext = false; 
} 

這使用eval解析位的代碼,它使用ES.next圖案分解但不是有效的EcmaScript 5.其中聲明並且分配isESNext是有效的EcmaScript 3代碼雖然代碼的其餘部分所以應該在所有瀏覽器上運行。

你正在運行到問題是由於Chapter 16

16 Errors

An early error is an error that can be detected and reported prior to the evaluation of any construct in the Program containing the error. An implementation must report early errors in a Program prior to the first evaluation of that Program.

...

An implementation must treat any instance of the following kinds of errors as an early error:

  • Any syntax error.

但上面的代碼段都繞早誤差,因爲

Early errors in eval code are reported at the time eval is called

+0

沒有你讀? ** Chrome **中的這個缺陷,我的懷疑是另一個......我很抱歉已經很厚,但我解釋了這個問題。 我會開始,我需要一些可以在所有瀏覽器中工作的東西,指出如果可能的話,瀏覽器支持** javascript1.7 **。謝謝; –

+1

@GuilhermeNascimento請民事。 – alex

+0

我已經道歉了,好嗎?我希望你能讀到我在問題中寫下的所有內容,以便理解我的疑惑,如果你能幫助我,我會很感激。 –

相關問題