Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

最优美的JS代码 #4

Closed
brickspert opened this issue Sep 15, 2017 · 8 comments
Closed

最优美的JS代码 #4

brickspert opened this issue Sep 15, 2017 · 8 comments

Comments

@brickspert
Copy link
Owner

记录看到的最优美的JS代码

@brickspert
Copy link
Owner Author

求数组中最大项

var arr = [1, 20, 22, 50, 11, 22];
var max = Math.max.apply(Math, arr);

@yueshuiniao
Copy link

求数组中最大项

var arr = [1, 20, 22, 50, 11, 22];
var max = Math.max(...arr);

@brickspert
Copy link
Owner Author

前端错误记录到后端

function logError(sev, msg){
        var img = new Image();
        img.src = "log.php?sev=" + encodeURIComponent(sev) + "&msg=" +
                  encodeURIComponent(msg);
}

@hazeFlame
Copy link

去重
Array.from(new Set([1,2,3,1,2,1,1,1,1,1]))

@yueshuiniao
Copy link

去重

[...new Set([1,2,3,1,2,1,1,1,1,1])]

@blockmood
Copy link

blockmood commented Dec 12, 2017

准确检测数据类型
Object.prototype.toString.call(val) == '[object ...]'

@Miller547719886
Copy link

最大值这样也行
Math.max.call(...arr)

@Misaka-0x447f
Copy link

@Miller547719886
.call/.apply没啥区别的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants