TAILIEUCHUNG - Test Driven JavaScript Development- P10

Test Driven JavaScript Development- P10:This book is about programming JavaScript for the real world, using the techniques and workflow suggested by Test-Driven Development. It is about gaining confidence in your code through test coverage, and gaining the ability to fearlessly refactor and organically evolve your code base. It is about writing modular and testable code. It is about writing JavaScript that works in a wide variety of environments and that doesn’t get in your user’s way. | Strict Mode 173 results in only the last one to be reachable inside the function except through arguments in which all parameters are always reachable . Listing shows the new behavior compared to the current one. Listing Using the same identifier for more than one formal parameter test repeated identifiers in parameters function Syntax error in ES5 strict mode function es3VsEs5 a a a use strict return a true in ES3 assertEquals 6 es3VsEs5 2 3 6 Attempts to access the caller or callee properties of the arguments object will throw a TypeError in strict mode. In ES3 and non-strict ES5 the arguments object shares a dynamic relationship with formal parameters. Modify a formal parameter and the value in the corresponding index of the argument object is modified too. Modify a value of the arguments object and the corresponding parameter changes. In strict mode this relationship goes away and arguments is immutable as Listing exemplifies. Listing Relationship between arguments and formal parameters function switchArgs a b use strict var c b b a a c return . arguments TestCase ArgumentsParametersTest test should switch arguments function Passes on ES5 strict mode assertEquals 3 2 switchArgs 2 3 Passes on ES3 assertEquals 2 3 switchArgs 2 3 Please purchase PDF Split-Merge on to remove this watermark. From the Library of 174 ECMAScript 5th Edition this is no longer coerced to an object in strict mode. In ES3 and non-strict ES5 this will be coerced to an object if it is not one already. For instance when using call or apply with function objects passing in null or undefined will no longer cause this inside the called function to be coerced into the global object. Neither will primitive values used as this be coerced to wrapper objects. Objects Properties and Variables eval and arguments cannot be used as identifiers in ES5 strict mode. Formal parameters variables the exception object in a try-catch .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.