kinky.htm JavaScript 奇巧淫技 JavaScript 奇巧淫技 评级组件 "★★★★★☆☆☆☆☆".slice(5 - rate, 10 - rate); // 定义一个变量rate是1到5的值 输出单词 ++[[]][+[]]+[+[]] (!(~+[])+{})[--[~+""][+[]]*[~+[]] + ~
JavaScript 奇巧淫技 JavaScript 奇巧淫技
评级组件
"★★★★★☆☆☆☆☆".slice(5 - rate, 10 - rate); // 定义一个变量rate是1到5的值输出单词
++[[]][+[]]+[+[]](!(~+[])+{})[--[~+""][+[]]*[~+[]] + ~~!+[]]+({}+[])[[~!+[]]*~+[]]([][[]]+[])[+!![]]+([]+{})[!+[]+!![]]错误处理的正确姿势
try { something } catch (e) { window.location.href = "http://stackoverflow.com/search?q=[js]+" + e.message }所有元素边框加色
[].forEach.call($$("*"), a => {a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)})随机字符串
Math.random().toString(16).substring(2) // 13位 Math.random().toString(36).substring(2) // 11位匿名函数自执行
(function(){}()); (function(){})(); [function(){}()]; ~function(){}(); !function(){}(); +function(){}(); -function(){}(); delete function(){}(); typeof function(){}(); void function(){}(); new function(){}(); new function(){}; var f = function(){}(); 1, function(){}(); 1 ^ function(){}(); 1 > function(){}(); // ...取整
~~2.33 2.33 | 0 2.33 >> 0货币格式化 1,234,567,890
'1234567890'.replace(/\B(?=(\d{3})+(?!\d))/g, ',')'1234567890'.split('').reverse().reduce((prev, next, index) => (index % 3 ? next : next + ',') + prev)两个整数交换数值
var a=1,b=2; a += b; b = a - b; a -= b; // 缺点也很明显,整型数据溢出,对于32位字符最大表示数字是2147483647a ^= b; b ^= a; a ^= b; // 位操作数组特性
[...new Set([1, "1", 2, 1, 1, 3])] // 去重Array(6).fill(8) // 重复数组var numbers = [5, 458 , 120 , -215 , 228 , 400 , 122205, -85411]; Math.max.apply(Math, numbers) Math.max(...numbers) // 数组最大值Array.prototype.slice.call(arguments) Array.from(arguments) // 将argruments对象转换成数组一个数组中找到一个数 find([0,1,2,3,4,5], 2) function find (x, y) { for (let i = 0; i < x.length; i++) if (x[i] == y) return i; }const find = (g => g(g)) (f => (next => (x, y, i = 0) => i >= x.length ? null : x[i] == y ? i : next(x, y, i+1))((...args) => f(f)(...args)))数字运算
parseInt(0.0000008) // 80.1 + 0.2 // 0.30000000000000004, 使用 ES6 的 Number.EPSILON 来更正参考
- https://github.com/jawil/blog/issues/24
- https://en.wikipedia.org/wiki/JSFuck
- https://esolangs.org/wiki/JSFuck
- http://patriciopalladino.com/blog/2012/08/09/non-alphanumeric-javascript.html
- https://raw.githubusercontent.com/aemkei/jsfuck/master/jsfuck.js