Sce*_*sto 13 javascript testing function
请耐心等待.
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() {
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) { //multiplication, inverse, one, concatenation, getObjectProperty, setObjectProperty
return (function(a, d) { //add, divide
return (function(s, t) { //subtract, ten
return (function(r, n) { //roundToTenDigits (fix for negatives), numbers (so you can call numbers as variables)
return (function(f) { //makes it so you don't have to re-initialize the functions every time you do math
return (f).apply(null, Array(g, h, function(x, y) {
return (r(a(x, y))) //modifies addition (rounds results like -2.999999999996)
}, function(x, y) {
return (r(s(x, y))) //modifies subtraction
}, function(x, y) {
return (r(m(x, y))) //modifies multiplication
}, d, c, function() { //makes a number out of its digits
return (Number(Object.keys(arguments).map(function(k) {
return (g(arguments, k))
}).join(String())))
}).concat(n)) //adds all the numbers to the arguments array
})
})(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)
考虑到我想要实现的性质,我认为我不能将此称为javascript中的错误,但如果存在最大数量的匿名函数(如果存在的话),那么最好有文档.例如,图书馆).
以前有人见过这样的事吗?有什么建议?
非常感谢.
PS请避免"你的假设是愚蠢的"答案.那太好了.
编辑:到目前为止只是对话的更新:
为了澄清,我不希望它输出function anonymous() function anonymous().我希望它输出function anonymous(x, y) function anonymous(x, y, z).
Chrome v43无法在Windows 8.1,Windows 7或Mac OS X 10上运行.
Firefox 39不起作用.
Chrome Canary v45完美运行.另一位用户说v44也有效.
我希望尽可能具有跨浏览器兼容性.
我是这段代码的作者.
如果您认为我的代码是以一种奇怪的方式编写的,那么您显然还没有读过这整个问题.
现代版本的 Chrome、Opera、Safari 和 Edge 都可以正常运行。
Firefox 仍然记录不带参数的函数,但由于现在它在所有三个版本的代码之间统一执行此操作,因此该错误似乎已得到解决。我认为这种显示选择是开发人员有意识的选择。
如果 Firefox 能够通过正确显示函数参数来加入 Chrome、Opera、Safari 和 Edge 的行列,那么如果能从 Mozilla 看到有关此问题的更多文档就更好了。