当前位置:首页 > 开发 > Web前端 > JavaScript > 正文

JavaScript学习笔记

发表于: 2015-01-11   作者:darrenzhu   来源:转载   浏览次数:
摘要: Repeated and Omitted Declarations It is legal and harmless to declare a variable more than once with the var statement. If the repeated declaration has an initializer, it acts as if it were simply an
Repeated and Omitted Declarations
It is legal and harmless to declare a variable more than once with the var statement. If the repeated declaration has an initializer, it acts as if it were simply an assignment statement.


JavaScript’s function scope means that all variables declared within a function are visible
throughout the body of the function. Curiously, this means that variables are even
visible before they are declared. This feature of JavaScript is informally known as hoisting:
JavaScript code behaves as if all variable declarations in a function (but not any
associated assignments) are “hoisted” to the top of the function. Consider the following
code:
var scope = "global";
function f() {
console.log(scope); // Prints "undefined", not "global"
var scope = "local"; // Variable initialized here, but defined everywhere



"use strict" is a directive introduced in ECMAScript 5. Directives are not statements
(but are close enough that "use strict" is documented here).

The strict mode of ECMAScript 5 is a restricted
subset of the language that fixes a few important language deficiencies and provides
stronger error checking and increased security. The differences between strict mode
and non-strict mode are the following (the first three are particularly important):
- The with statement is not allowed in strict mode.
- In strict mode, all variables must be declared: a ReferenceError is thrown if you
assign a value to an identifier that is not a declared variable, function, function
parameter, catch clause parameter, or property of the global object. (In non-strict
mode, this implicitly declares a global variable by adding a new property to the
global object.)
- In strict mode, functions invoked as functions (rather than as methods) have a
this value of undefined. (In non-strict mode, functions invoked as functions are
always passed the global object as their this value.) This difference can be used to
determine whether an implementation supports strict mode:
var hasStrictMode = (function() { "use strict"; return this===undefined}());
Also, in strict mode, when a function is invoked with call() or apply(), the this
value is exactly the value passed as the first argument to call() or apply(). (In
nonstrict mode, null and undefined values are replaced with the global object and
non-object values are converted to objects.)
- In strict mode, assignments to nonwritable properties and attempts to create new
properties on nonextensible objects throw a TypeError. (In non-strict mode, these
attempts fail silently.)
- In strict mode, code passed to eval() cannot declare variables or define functions
in the caller’s scope as it can in non-strict mode. Instead, variable and function
definitions live in a new scope created for the eval(). This scope is discarded when
the eval() returns.
- In strict mode, the arguments object (§8.3.2) in a function holds a static copy of
the values passed to the function. In non-strict mode, the arguments object has
“magical” behavior in which elements of the array and named function parameters
both refer to the same value.
- In strict mode, a SyntaxError is thrown if the delete operator is followed by an
unqualified identifier such as a variable, function, or function parameter. (In nonstrict
mode, such a delete expression does nothing and evaluates to false.)
- In strict mode, an attempt to delete a nonconfigurable property throws a
TypeError. (In non-strict mode, the attempt fails and the delete expression evaluates
to false.)
- In strict mode, it is a syntax error for an object literal to define two or more properties
by the same name. (In non-strict mode, no error occurs.)
- In strict mode, it is a syntax error for a function declaration to have two or more
parameters with the same name. (In non-strict mode, no error occurs.)

JavaScript学习笔记

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
1.什么是JavaSript HTML只是描述页面长相的标记语言,没有计算,判断能力,如果所有计算,判断(比如判断
  目前所见的,在普通的JavaScript应用中和绝大多数人一样使用的是全局的方式。大概是因为JavaScr
玩了好几天,玩的也好累了,天天打dota,打cf,和弟弟两个人开黑,然后老是被杀,弄得英雄1200的初
前言 DOM介绍 1、DOM基本知识 2、DOM操作 3、DOM类型 前言 DOM (文档对象模型)是对 HTML 和 XML 文
一.call方法: 调用一个对象的一个方法,以另一个对象替换当前对象(其实就是更改对象的内部指针,即
JavaScript基础: JavaScript 基础认识 JavaScript 对象定义 JavaScript 继承 JavaScript 事件 JavaS
记录以下网址的javascript core crash章节http://courses.coreservlets.com/Course-Materials/ajax-b
记录以下网址的javascript core crash章节http://courses.coreservlets.com/Course-Materials/ajax-b
学习参拷:http://www.cnblogs.com/TomXu/archive/2011/12/15/2288411.html 第一节:基础 1.1:变量
1.什么是原型? 原型是一个对象,其他对象可以通过它实现属性继承。 这里有两个概念,我第一次看原
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号