/*
官网原文:
In JScript the identifier in a function expression is visible in the enclosing scope because such expressions are treated as function declarations. Example:
*/
<script>
var foo = function bar(b)
{
if (b == true)
{
bar(); // works because bar is visible inside itself
}
else
{
document.write("hello");
}
}
foo();
// works because foo is a ref to Function object bar(false);
// should fail because bar is not visible here
</script>
/* Output:
IE: prints "hellohello"
FF: prints “hello” followed by syntax error (bar is not defined)
Opera: prints “hello” followed by ReferenceError (Reference to undefined variable: bar)
Safari: prints “hello”
*/
/*
Note: IE treats nested function expressions containing a function name as a function declaration that is scoped to the enclosing function (applying the second bullet rule from §10.1.3 instead of case 3 of the semantics in §13. In the following example the forward reference to x gets resolved in IE, whereas we get a syntax error in FF and TypeError in Opera. Example:
*/
<script>
function f(x)
{
x();
y = function x()
{
document.write("inner called ")
};
document.write(x);
document.write(arguments[0]);
}
document.write("test 4 ");
f("param");
</script>
/*
Output:
IE: test 4 inner called function x() {document.write("inner called ")}function x() {document.write("inner called ")}
FF: test 4 Opera: test 4
Safari: test 4
Here is another example of the same issue:
*/
<script>
function foo()
{
function bar() {}
var x = function baz(z)
{
document.write("baz" + z);
if (z) baz(false);
};
x(true); // legal;
bar(); // legal
baz(true); // should be illegal, is legal
}
foo();
</script>
/* The function statement bar should add “bar” to foo‟s variable object. The function expression baz should NOT add “baz” to foo‟s variable object, but it should be in scope when baz is called, so that it can do the recursive call.
Output: IE: baztruebazfalsebaztruebazfalse
FF: baztruebazfalse (followed by an error – baz not defined)
Opera: same as FF
*/
分享到:
相关推荐
Callbacks, Promises and Deferreds, Code Quality, Function Polymorphism, Function Scope, Hoisting and Closures, Functional Programming and Stateless Functions, Immediately Invoked Function Expressions,...
Pointers and Function Arguments Pointers and Arrays Address Arithmetic Character Pointers and Functions Pointer Arrays; Pointers to Pointers Multi-dimensional Arrays Initialization of Pointer ...
32位版本的 PLSQL 正式版。...Test Window bind variable scan function could fail when using q'<string>' expressions Table.column highlighting did not always work within if-then-else statements
Pointers and Function Arguments Pointers and Arrays Address Arithmetic Character Pointers and Functions Pointer Arrays; Pointers to Pointers Multi-dimensional Arrays Initialization of Pointer ...
64位版本的 PLSQL 正式版,只能运行在64...Test Window bind variable scan function could fail when using q'<string>' expressions Table.column highlighting did not always work within if-then-else statements
link: function(scope, element, attrs) { // 动态调整导航栏样式 } }; }); ``` 3. **状态管理和路由**:AngularJS的路由机制支持单页面应用中不同视图之间的切换,通过结合媒体查询等技术,可以在不同设备上...
They inherit the `this` value from the enclosing context, eliminating common issues related to the `this` keyword in traditional function expressions. For example: ```javascript const values = [0, 3...
The function Statement Versus the function Expression Section B.10. Typed Wrappers Section B.11. new Section B.12. void Appendix C. JSLint Section C.1. Undefined Variables and Functions Section...
Variable Scope x Parameters x Local Variables and Global Variables with the Same Name x Where to Put Function Defintions x The Colon : x Step by Step, One More Time x Designing the Program x A Web ...
app.controller('myCtrl', function($scope) { $scope.message = "Hello, AngularJS!"; }); ``` 这段代码展示了如何创建一个名为`myApp`的应用,并定义了一个`myCtrl`控制器,将`message`变量绑定到视图上。...
The PL/SQL function result cache is a new feature that caches the results of a function call based on its input parameters. This can significantly improve the performance of applications by avoiding ...
app.controller('MyCtrl', function($scope) { $scope.name = 'John'; }); ``` ### 4. $scope $scope是连接控制器和视图的桥梁,它是应用程序中数据的容器。它提供了事件广播、watch等功能,帮助我们管理数据和...
2. **Scope作为Expressions的上下文**:在模板中,我们可以使用表达式(Expressions)来访问Scope中的数据。例如,`{{ myVar }}`会显示`$scope.myVar`的值。表达式的计算依赖于当前作用域的环境。 3. **Scope的事件...
- **Function Heading**: Explanation of the syntax for defining a function, including return type, name, and parameters. - **Function Body**: Description of the block of code that performs the actual ...
Call by Value Character Arrays External Variables and Scope <br>Chapter 2: Types, Operators and Expressions Variable Names Data Types and Sizes Constants Declarations ...
myApp.controller('MyController', function($scope) { $scope.message = 'Hello, AngularJS!'; }); ``` **三、服务(Service)** 服务是可复用的、单例的对象,它们提供跨控制器的数据共享和功能封装。AngularJS...
including the edition-based redefinition capability, the function result cache, the new CONTINUE statement, fine-grained dependency tracking, sequences in PL/SQL expressions, supertype invocation ...