当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 奇妙的js

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 奇妙的js


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 58 ::
收藏到网摘: n/a

复制代码 代码如下:

>>> function a(){function b(){return "aaa"} Function.prototype.c=function(){return b();}}
>>> a()
>>> a.c
function()
>>> a.c()
"aaa"
>>> a.hasOwnProperty("c")
false

看这段代码,首先声明一个函数a,内部又定义了一个函数b,但是函数b不是函数对象a的方法,只是函数a块当中的临时变量函数(或者说私有函数,不知道怎么描述好),后面又定义了一个函数c是用function(){}在a内部定义的,所以会产生closure所以c可以遍历到a下面所有块内部变量,当然包括b,我又把c挂到了Function.prototype下面,就是不是直接挂a下,而是挂到a的原形链上,最后还是执行出来了,并且hasOwnProperty也是假,更有
代码
复制代码 代码如下:

>>> d={};
Object
>>> function a(){function b(){return "aaa"} d.c=function(){return b();}}
>>> a()
>>> d.c()
"aaa"

closure和函数执行的context一点关系没有,context可以用call apply方法改变this,可是closure在function定义后好似没有办法再修改了,不知道是不是这样