严格模式和保留字

时间:2015-11-09 07:49:44

标签: javascript strict-mode

为什么这段代码很好:

Nov 9 11:11:43 [Genymotion] [Warning] Genymotion Version: Genymotion 2.5.2 
Nov 9 11:11:43 [Genymotion] [Debug] [LaunchpadApp] Started with ("./genymotion") 
Nov 9 11:11:44 [Genymotion] [Debug] [doRequest] Requesting:  "https://cloud.genymotion.com/launchpad/last_version/linux/x64/" 
Nov 9 11:11:44 [Genymotion] [Debug] Getting currently authenticated user from  local cache 
Nov 9 11:11:44 [Genymotion] [Warning] QNativeImage: Unable to attach to shared memory segment. 
Nov 9 11:11:44 [Genymotion] [Warning] QPainter::begin: Paint device returned engine == 0, type: 3
Nov 9 11:11:44 [Genymotion] [Warning] QPainter::setCompositionMode: Painter not active
Nov 9 11:11:44 [Genymotion] [Warning] X Error: BadDrawable (invalid Pixmap or Window parameter) 9
  Major opcode: 62 (X_CopyArea)
  Resource id:  0x0
Nov 9 11:11:44 [Genymotion] [Debug] [doRequest] HTTP Status: 0 
Nov 9 11:11:44 [Genymotion] [Debug] [doRequest] HTTP Content: "" 
Nov 9 11:11:44 [Genymotion] [Debug] [doRequest] Reply error: "Proxy connection refused" ( 99 ) 
Nov 9 11:11:44 [Genymotion] [Debug] [doRequest] last error msg: "Unknown proxy error" 
Nov 9 11:11:44 [Genymotion] [Error] Network error while retrieving JSON content:  7 
Nov 9 11:11:44 [Genymotion] [Error] [getGenymotionLastVersion] Bad request: "/launchpad/last_version/linux/x64/" 
Nov 9 11:11:44 [Genymotion] [Warning] QPainter::begin: Paint device returned engine == 0, type: 3
Nov 9 11:11:44 [Genymotion] [Warning] QPainter::setCompositionMode: Painter not active
Nov 9 11:11:44 [Genymotion] [Error] Unable to get last Genymotion version number from server:  7 
Nov 9 11:11:44 [Genymotion] [Debug] [login] Trying to authenticate  "mousa_mk" 
Nov 9 11:11:44 [Genymotion] [Debug] Trying to logout user 
Nov 9 11:11:44 [Genymotion] [Debug] [doRequest] Requesting:  "https://cloud.genymotion.com/launchpad/login/" 
Nov 9 11:11:44 [Genymotion] [Warning] X Error: BadDrawable (invalid Pixmap or Window parameter) 9
  Major opcode: 62 (X_CopyArea)
  Resource id:  0x0
Nov 9 11:11:44 [Genymotion] [Debug] [doRequest] HTTP Status: 0 
Nov 9 11:11:44 [Genymotion] [Debug] [doRequest] HTTP Content: "" 
Nov 9 11:11:44 [Genymotion] [Debug] [doRequest] Reply error: "Proxy connection refused" ( 99 ) 
Nov 9 11:11:44 [Genymotion] [Debug] [doRequest] last error msg: "Unknown proxy error" 
Nov 9 11:11:44 [Genymotion] [Error] [login] Login process result: 7 
Nov 9 11:11:44 [Genymotion] [Warning] QPainter::begin: Paint device returned engine == 0, type: 3
Nov 9 11:11:44 [Genymotion] [Warning] QPainter::setCompositionMode: Painter not active
Nov 9 11:11:44 [Genymotion] [Debug] Loading "vboxmanage" plugin 
Nov 9 11:11:44 [Genymotion] [Warning] X Error: BadDrawable (invalid Pixmap or Window parameter) 9
  Major opcode: 62 (X_CopyArea)
  Resource id:  0x0
Nov 9 11:11:44 [Genymotion] [Debug] Plugin "vboxmanage" loaded 
Nov 9 11:11:44 [Genymotion] [Debug] Chipset: "GenuineIntel" 
Nov 9 11:11:44 [Genymotion] [Debug] CPUID 0x1 (Intel): ECX= "1dbae3bf" 
Nov 9 11:11:44 [Genymotion] [Debug] [VBoxManageCore] Path: "VBoxManage" 
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("list", "hostinfo") returns 0 
Nov 9 11:11:44 [Genymotion] [Debug] [System properties] Online physical CPU number: 4 
Nov 9 11:11:44 [Genymotion] [Debug] [System properties] Online virtual CPU number: 2 
Nov 9 11:11:44 [Genymotion] [Debug] [System properties] Max CPU number: 8 
Nov 9 11:11:44 [Genymotion] [Debug] [System properties] Max memory size: 7917 
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("list", "hostonlyifs") returns 0 
Nov 9 11:11:44 [Genymotion] [Debug] [VBoxManageCore] Checking status of interface "vboxnet0" "192.168.56.1" 
Nov 9 11:11:44 [Genymotion] [Debug] [VBoxManageCore] "vboxnet0" is OK 
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("list", "dhcpservers") returns 0 
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("--version") returns 0 
Nov 9 11:11:44 [Genymotion] [Debug] VM engine version: "5.0.4_Ubuntur102546" 
Nov 9 11:11:44 [Genymotion] [Debug] VMX/SVM CPU availability: true 
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("--version") returns 0 
Nov 9 11:11:44 [Genymotion] [Debug] VM engine version: "5.0.4_Ubuntur102546" 
Nov 9 11:11:44 [Genymotion] [Warning] QPainter::begin: Paint device returned engine == 0, type: 3
Nov 9 11:11:44 [Genymotion] [Warning] QPainter::setCompositionMode: Painter not active
Nov 9 11:11:44 [Genymotion] [Warning] X Error: BadDrawable (invalid Pixmap or Window parameter) 9
  Major opcode: 62 (X_CopyArea)
  Resource id:  0x0
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("list", "vms") returns 0 
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("guestproperty", "enumerate", "2d9b3a13-d8af-412a-bbeb-e7f713b4b42d") returns 0 
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("guestproperty", "enumerate", "76afb120-f753-4474-bbc9-53c18cc77576") returns 0 
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("guestproperty", "enumerate", "4f274f87-41ec-4998-9860-224869634750") returns 0 
Nov 9 11:11:44 [Genymotion] [Warning] QPainter::begin: Paint device returned engine == 0, type: 3
Nov 9 11:11:44 [Genymotion] [Warning] QPainter::setCompositionMode: Painter not active
Nov 9 11:11:44 [Genymotion] [Warning] X Error: BadDrawable (invalid Pixmap or Window parameter) 9
  Major opcode: 62 (X_CopyArea)
  Resource id:  0x0
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("guestproperty", "enumerate", "Custom Phone - 5.1.0 - API 22 - 768x1280") returns 0 
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("showvminfo", "Custom Phone - 5.1.0 - API 22 - 768x1280") returns 0 
Nov 9 11:11:44 [Genymotion] [Error] VBoxManage ("guestproperty", "enumerate", "443b5e7d-fb22-4070-a2ae-1ddcf4ccc1c7") returns 1 
Nov 9 11:11:44 [Genymotion] [Error] Output command: "VBoxManage: error: The object functionality is limited
VBoxManage: error: Details: code E_ACCESSDENIED (0x80070005), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "LockMachine(a->session, LockType_Shared)" at line 253 of file VBoxManageGuestProp.cpp" 
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("guestproperty", "enumerate", "74ce8294-3c0c-4b8f-a1a6-b443fe0fdcac") returns 0 
Nov 9 11:11:44 [Genymotion] [Debug] VBoxManage ("guestproperty", "enumerate", "Google Nexus 4 - 5.1.0 - API 22 - 768x1280") returns 0 
Nov 9 11:11:45 [Genymotion] [Debug] VBoxManage ("showvminfo", "Google Nexus 4 - 5.1.0 - API 22 - 768x1280") returns 0 
Nov 9 11:11:45 [Genymotion] [Warning] QPainter::begin: Paint device returned engine == 0, type: 3
Nov 9 11:11:45 [Genymotion] [Warning] QPainter::setCompositionMode: Painter not active
Nov 9 11:11:45 [Genymotion] [Warning] QPainter::begin: Paint device returned engine == 0, type: 3
Nov 9 11:11:45 [Genymotion] [Warning] QPainter::setCompositionMode: Painter not active
Nov 9 11:11:45 [Genymotion] [Warning] X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62 (X_CopyArea)
Resource id:  0x0
Nov 9 11:11:45 [Genymotion] [Warning] X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62 (X_CopyArea)
Resource id:  0x0
Nov 9 11:11:45 [Genymotion] [Warning] QNativeImage: Unable to attach to shared memory segment. 
Nov 9 11:11:45 [Genymotion] [Warning] X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62 (X_CopyArea)
Resource id:  0x0
Nov 9 11:11:45 [Genymotion] [Warning] QNativeImage: Unable to attach to shared memory segment. 
Nov 9 11:11:45 [Genymotion] [Warning] X Error: BadPixmap (invalid Pixmap parameter) 4
Major opcode: 56 (X_ChangeGC)
Resource id:  0x0
Nov 9 11:11:45 [Genymotion] [Warning] X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62 (X_CopyArea)
Resource id:  0x0
Nov 9 11:11:45 [Genymotion] [Warning] X Error: BadPixmap (invalid Pixmap parameter) 4
Major opcode: 56 (X_ChangeGC)
Resource id:  0x0
Nov 9 11:11:45 [Genymotion] [Warning] X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62 (X_CopyArea)
Resource id:  0x0
Nov 9 11:11:48 [Genymotion] [Warning] X Error: BadPixmap (invalid Pixmap parameter) 4
Major opcode: 56 (X_ChangeGC)
Resource id:  0x0
Nov 9 11:11:48 [Genymotion] [Warning] X Error: BadPixmap (invalid Pixmap parameter) 4
Major opcode: 56 (X_ChangeGC)
Resource id:  0x0
Nov 9 11:11:48 [Genymotion] [Warning] X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62 (X_CopyArea)
Resource id:  0x0

虽然这不是

.Genymotion

我知道接口是严格模式下的保留字,但两个示例都不应该抛出错误吗?

2 个答案:

答案 0 :(得分:9)

"use strict";需要是函数(或脚本中,如果脚本范围内)的第一个语句,以触发严格模式;在其他任何地方,你也可以写"merry christmas";

答案 1 :(得分:4)

第一个示例实际上并未启用严格模式。见https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#Invoking_strict_mode

  

严格模式适用于整个脚本各个功能。它不适用于{}括号中的块语句;试图将它应用于这种情境并没有任何作用。