请耐心等待.
tl; dr我的代码仅在我在函数参数之间添加换行符时才有效.javascript中每行的堆栈大小或函数声明是否有最大值?
我一直在测试我的一个假设,如果你有足够的创造力,所有的javascript函数都可以重写(通过牺牲速度和可读性)而不使用:
""
,[]
,0
,false
,{}
,等.)或者,用外行人的话说,整个功能应该匹配/^[a-zA-Z(){}.,]*$/
.
到目前为止,我在证明这个假设的过程中遇到的最大挑战(我没有得到正则表达式,这应该是有趣的)是处理数学,它严重依赖于运算符和数字.
我写了跟随我的参数的函数,并且:
add(a,b) //a+b
)digs(one,three,six,eight) //1368
)setprop(a,b,c) //a[b]=c
)一般的想法是构造如下所示的函数,以这种方式使算法稍微更具可读性和可写性:
function(...){(function(add,morefuncs...){algorithm...})(function(){...},morefuncs...)}
Run Code Online (Sandbox Code Playgroud)
我的功能可以单独工作,也可以在这种形式下工作,但是当我添加更多功能时,我注意到了一个非常特殊的错误:
//For some reason, this breaks:
func(arguments,...,f1,f2)
//And this doesn't:
func(arguments,...,
f1,f2)
Run Code Online (Sandbox Code Playgroud)
鉴于我的代码需要大量的匿名函数,我假设javascript可以在一行中处理最大数量的匿名函数,但我找不到任何说明这个或其他的文档.
以下是我的代码的三个版本:
版本1:没有换行符,不起作用
(function(){return(function(domath){return(domath)(function(getprop,setprop,add,sub,mlt,div,cct,digs,zero,one,two,three,four,five,six,seven,eight,nine){console.log(getprop,setprop)})})((function(){return(function(m,i,o,c,g,h){return(function(a,d){return(function(s,t){return(function(r,n){return(function(f){return(f).apply(null,Array(g,h,function(x,y){return(r(a(x,y)))},function(x,y){return(r(s(x,y)))},function(x,y){return(r(m(x,y)))},d,c,function(){return(Number(Object.keys(arguments).map(function(k){return(g(arguments,k))}).join(String())))}).concat(n))})})(function(x){return(Number(x.toFixed(t)))},Array(Number(),Math.exp(Number()),Array(Number(),String()).toString().length,Array(Number(),Number()).toString().length,Boolean(Math.exp(Number())).toString().length,Boolean(Number()).toString().length,Array(Boolean(),String()).toString().length,Array(Boolean(),Number()).toString().length,Array(Boolean(),Number(),String()).toString().length,Array(Boolean(),Number(),Number()).toString().length))})(function(x,y){return(Math.log(d(Math.exp(x),Math.exp(y))))},Number(c(String(o),String(Number()))))})(function(x,y){return(Math.log(m(Math.exp(x),Math.exp(y))))},function(x,y){return(m(x,i(y)))})})(function(x,y){return(Math.log(Math.pow(Math.exp(x),y)))},function(x){return(Math.pow(x,Array().indexOf(Number())))},Math.exp(Number()),function(x,y){return(Array(x,y).join(String()))},function(x,y){return(Object.getOwnPropertyDescriptor(x,y).value)},function(x,y,z){Object.defineProperty(x,y,Object.getOwnPropertyDescriptor(Array(z,Number()).slice(Number(),Math.exp(Number())),Number()))})})())})()
Run Code Online (Sandbox Code Playgroud)
登录function anonymous(urn) function anonymous(urn)
Chrome.(什么是"urn"?我没有该名称的任何变量,并且该字符串的唯一实例是"return"关键字.)
登录function anonymous() function anonymous()
Firefox.
版本2:有一个换行符,有效
(function(){return(function(domath){return(domath)(function(getprop,setprop,add,sub,mlt,div,cct,digs,zero,one,two,three,four,five,six,seven,eight,nine){console.log(getprop,setprop)})})((function(){return(function(m,i,o,c,g,h){return(function(a,d){return(function(s,t){return(function(r,n){return(function(f){return(f).apply(null,Array(g,h,function(x,y){return(r(a(x,y)))},function(x,y){return(r(s(x,y)))},function(x,y){return(r(m(x,y)))},d,c,function(){return(Number(Object.keys(arguments).map(function(k){return(g(arguments,k))}).join(String())))}).concat(n))})})(function(x){return(Number(x.toFixed(t)))},Array(Number(),Math.exp(Number()),Array(Number(),String()).toString().length,Array(Number(),Number()).toString().length,Boolean(Math.exp(Number())).toString().length,Boolean(Number()).toString().length,Array(Boolean(),String()).toString().length,Array(Boolean(),Number()).toString().length,Array(Boolean(),Number(),String()).toString().length,Array(Boolean(),Number(),Number()).toString().length))})(function(x,y){return(Math.log(d(Math.exp(x),Math.exp(y))))},Number(c(String(o),String(Number()))))})(function(x,y){return(Math.log(m(Math.exp(x),Math.exp(y))))},function(x,y){return(m(x,i(y)))})})(function(x,y){return(Math.log(Math.pow(Math.exp(x),y)))},function(x){return(Math.pow(x,Array().indexOf(Number())))},Math.exp(Number()),function(x,y){return(Array(x,y).join(String()))},
function(x,y){return(Object.getOwnPropertyDescriptor(x,y).value)},function(x,y,z){Object.defineProperty(x,y,Object.getOwnPropertyDescriptor(Array(z,Number()).slice(Number(),Math.exp(Number())),Number()))})})())})()
Run Code Online (Sandbox Code Playgroud)
日志function anonymous(x, y) function anonymous(x, y, z)
.
版本3:因您的观赏乐趣而美化
(function() …
Run Code Online (Sandbox Code Playgroud)