"use strict";
Về cơ bản nó cho phép chế độ nghiêm ngặt.
Strict Mode is a feature that allows you to place a program, or a function, in a "strict" operating context. In strict operating context, the method form binds this to the objects as before. The function form binds this to undefined, not the global set objects.
Theo nhận xét của bạn, bạn sẽ nói một số khác biệt sẽ có ở đó. Nhưng đó là giả định của bạn. Mã Node.js không là gì ngoài mã JavaScript của bạn. Tất cả mã Node.js được diễn giải bởi V8 JavaScript engine. Động cơ JavaScript V8 là một công cụ JavaScript mã nguồn mở do Google phát triển cho trình duyệt web Chrome.
Vì vậy, sẽ không có sự khác biệt lớn về cách trình duyệt Chrome và Node.js.
Vui lòng đọc chế độ nghiêm ngặt trong JavaScript là gì.
Để biết thêm thông tin:
- Strict mode
- ECMAScript 5 Strict mode support in browsers
- Strict mode is coming to town
- Compatibility table for strict mode
- Stack Overflow questions: what does 'use strict' do in JavaScript & what is the reasoning behind it
ECMAScript 6:
ECMAScript 6 Mã & chế độ nghiêm ngặt. Sau đây là tóm tắt from the specification:
10.2.1 Strict Mode Code
An ECMAScript Script syntactic unit may be processed using either unrestricted or strict mode syntax and semantics. Code is interpreted as strict mode code in the following situations:
- Global code is strict mode code if it begins with a Directive Prologue that contains a Use Strict Directive (see 14.1.1).
- Module code is always strict mode code.
- All parts of a ClassDeclaration or a ClassExpression are strict mode code.
- Eval code is strict mode code if it begins with a Directive Prologue that contains a Use Strict Directive or if the call to eval is a direct eval (see 12.3.4.1) that is contained in strict mode code.
- Function code is strict mode code if the associated FunctionDeclaration, FunctionExpression, GeneratorDeclaration, GeneratorExpression, MethodDefinition, or ArrowFunction is contained in strict mode code or if the code that produces the value of the function’s [[ECMAScriptCode]] internal slot begins with a Directive Prologue that contains a Use Strict Directive.
- Function code that is supplied as the arguments to the built-in Function and Generator constructors is strict mode code if the last argument is a String that when processed is a FunctionBody that begins with a Directive Prologue that contains a Use Strict Directive.
Ngoài ra nếu bạn đang bị mất trên những tính năng được hỗ trợ bởi phiên bản hiện tại của bạn Node.js, node.green này có thể giúp bạn (thúc đẩy từ các dữ liệu giống như kangax).
Nguồn
2013-08-24 10:30:27
Chuỗi 'sử dụng nghiêm ngặt'; 'trước bất kỳ câu lệnh nào của hàm sẽ đặt nó ở chế độ nghiêm ngặt (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope /Chế độ nghiêm ngặt). –
Bạn đã đọc sách này chưa? : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode –
điều này không trùng lặp ... Tôi thực sự không biết về JavaScript .. và nếu nó có trong JavaScript. một số khác biệt sẽ ở đó .. đúng không? Vì vậy, hãy cung cấp một số hiểu biết về node.js –