You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.
/* by 郑航 from https://www.zhihu.com/question/37904806/answer/74109099 */functiongetRating(rating){if(rating>5||rating<0)thrownewError('数字不在范围内');return'★★★★★☆☆☆☆☆'.substring(5-rating,10-rating);}
重复打印字符串n次
/* by 施浩宏 from https://www.zhihu.com/question/37904806/answer/74199322 */functionrepeat(n,str){returnnewArray(n+1).join(str)}
Github上有一个Javascript电子书系列比较火, 叫做You-Dont-Know-JS, 这里会总结一些里面比较有意思的东西,它处看到的也会放在这里。
用bind给console.log()设置别名
[ ].map(fn)利用内置函数转变数组值类型
巧用位运算
由于
~-1 === 0
, 而!0 === true
, 则可以在使用indexOf
方法的情况下用~
, 例如:合并/扁平化 嵌套数组
随机数应用
从数组中随机获取成员
获取指定范围内的随机数
生成随机的字母数字字符串
Tricks
slice(-2)
)TODO...
扩展阅读:
从一行CSS调试代码中学到的JavaScript知识
The text was updated successfully, but these errors were encountered: