• Javascript基础系列(六)-函数


    函数表达式,函数声明; 函数声明整体提升

    递归

    M1:
    	arguments.callee(); //调用自身,但在严格模式下无效
    	
    M2:
    	命名函数表达式
    	var fun2 = (function fun() {
    			...
    			fun();
    			...
    	});
    

    闭包

    有权访问另一个函数作用域中的变量的函数

    for(var i=0;i<10;i++) {
    	(function(j){
    		setTimeout(function(){
    			console.info(j);
    		}, 1000);
    	})(j);
    }
    

    模仿块级作用域

    if white for 声明的变量并不只存在于当前块级范围内

    for(var i=0;i<10;i++) {
    	console.info(i);
    }
    alert(i);
    
    模仿块级作用域
    (function(){
    	for(var i=0;i<10;i++){
    		console.info(i);
    	}
    })();
    alert(i);
    

    This

    The this keyword is relative to the execution context, not the declaration context.

    By default, this refers to the global object.

    为什么说是全局对象(the global object),因为非浏览器情况下(例如:nodejs)中全局变量并非window对象,而就是叫“全局变量”(the global object)。不过由于我们这片文章主要讨论的是前端开发知识,所以nodejs就被我们忽略了。

    在浏览器中setTimeout、setInterval和匿名函数执行时的当前对象是全局对象window

    var name = 'window-name';
    function Item() {
    	this.name ='zhangsan';
    	this.display = function() {
    		console.info(this.name);
    	};
    	this.show = function() {
    		setTimeout(this.display, 1000);
    	}
    }
    
    var item = new Item();
    item.show();
    item.display();
    
  • 相关阅读:
    运行时动态的创建form的方法
    用X++代码来动态的改变表的属性
    使用WinAPI类来查找文件
    用循环得到表中所有的字段
    用X++建立和调用报表(Report)
    JAVA 保留字
    Cygwin使用
    系统程序员成长计划-算法与容器(三) (上)
    系统程序员成长计划工程管理(二)
    系统程序员成长计划-算法与容器(三) (下)
  • 原文地址:https://www.cnblogs.com/pengsn/p/12690860.html
Copyright © 2020-2023  润新知