Functions Introduction # Functions are the fundamental building block of any application in JavaScript. They’re how you build up layers of abstraction, mimicking classes, information hiding, and modules. In TypeScript, while there are classes, namesp…
块级函数(Block-Level Functions) 在ES3及以前,在块内声明一个函数会报语法错误,但是所有的浏览器都支持块级函数.不幸的是,每个浏览器在支持块级函数方面都有一些细微的不同的行为.所以开发者最好不要在块内声明函数.为了解决浏览器在块内支持声明函数时带来的兼容性问题,在ES5中可以使用strict模式,这样如果开发者试图定义一个块内函数,就会报错: "use strict"; if (true) { //throws a syntax error in ES5 fun…
明确函数的双重作用(Clarifying the Dual Purpose of Functions) 在ES5及更早的ES版本中,函数调用时是否使用new会有不同的作用.当使用new时,函数内的this指向一个新对象并且函数会返回这个对象.看下面的代码: function Person(name) { this.name = name; } var person = new Person("Zakas"); var notAPerson = Person("Zakas&qu…
介绍 本章节我们要着重介绍的是一个非常常见的ECMAScript对象——函数(function),我们将详细讲解一下各种类型的函数是如何影响上下文的变量对象以及每个函数的作用域链都包含什么,以及回答诸如像下面这样的问题:下面声明的函数有什么区别么?(如果有,区别是什么). 原文:http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/ var foo = function () { ... }; 平时的惯用方式: function fo…
增强的Function构造函数(Increased Capabilities of the Function Constructor) 在Javascript中Function构造函数可以让你创建一个新函数,不过这个功能并不经常使用.Function构造函数接收函数参数和函数体作为参数,参数都必须是字符串.下面是一个例子: var add = new Function("first", "second", "return first+second"…
使用未命名参数(Working with Unnamed Parameters) JavaScript并不限制传递给函数的实参个数,你可以总是传递比形参个数多或者少的实参.在ES6中当向函数传递比形参个数少的实参时,就会使用默认参数值.当向函数传递比形参个数多的实参时,ES6同样有对应的方案使用.来看一个示例: function pick(object) { let result = Object.create(null); for (let i = 1, len = arguments.len…
Python中的描述符是一个相对底层的概念 descriptor Any object which defines the methods get(), set(), or delete(). When a class attribute is a descriptor, its special binding behavior is triggered upon attribute lookup. Normally, using a.b to get, set or delete an att…
新人一枚,这两天一直在研究lamp的搭建,感觉自己对apache理解的不够深彻,决定写这一篇(翻译)httpd.conf文件 未完待续 cat /usr/local/apache/conf/httpd.conf## This is the main Apache HTTP server configuration file. It contains the# configuration directives that give the server its instructions.# See…