Comments (44)
完全是 js 的糟粕吧。。。。各种隐式的代码背后的逻辑说不定那个版本就改了。。老老实实用官方 api 不好吗?
from blog.
无聊翻着看,看到说的 xx 邀请码,直接公司大屏幕搜了下....之前真不知道1024是个啥
from blog.
@IMLaoJI
typeof item + item
就是设置一个键,键名为值的类型 + 值。
然后查找这个缓存的对象里面有没有相同的键就知道这个值是不是遍历过了。
from blog.
@jawil 还得感谢GayHub啊... 一眼就看出来了...
from blog.
@xiyuyizhi 其实可以再深入一些,可以考虑带小数的情况
function formatNumber(num) {
return String(num).replace(/\d(?=(\d{3})+(\.\d+)?$)/g, '$&,');
}
from blog.
看到没人提,就提一下
var args = [...arguments]; 对于arguments对象是可以的
但是对一般的 {0:"a", 1:"b", length: 2} 这种是不行的,Array.from 都可以
from blog.
空数组导致reduce报错那个,看文档是因为
initialValue
用作第一个调用 callback的第一个参数的值。 如果没有提供初始值,则将使用数组中的第一个元素。 在没有初始值的空数组上调用 reduce 将报错。
所以initialValue不要空着,加上0就行了
let arr = []
function sum(arr) {
return arr.reduce((a, b) => a + b, 0)
}
sum(arr) //0
这样就不会报错了
from blog.
圣诞快乐,1024邀请码,有缘人得!
a6e1bbfa4e2e4bf7 | 2017-12-23 17:50:04 | | | 未使用 | 邀请
c7a5a23f4f0e5cc7 | 2017-12-23 17:50:04 | | | 未使用 | 邀请
from blog.
这是啥
from blog.
不可能改的,JavaScript 设计者都承认 null 是个对象都是一种错误的决定,也没看改过来,原因你懂得。
为了向下兼容,这些东西都是 ECMAScript 的东西,怎么能说不定就改了,对于 JavaScript 这种脚本语言,只可能拓展新的功能,不可能改变原来的功能的。
还有就是糟粕问题,完全不敢苟同,我觉得是玄学。@huyansheng3
from blog.
数组去重那部分小标题权重错了。。
from blog.
感谢指正,哈哈,这些细节都被看出来了 @axuebin
from blog.
大佬真的很会玩。。。最容易懂的才是好方法呀
from blog.
1.2 Promise 版本运行报错是为何
//我又仔细看了看,没有错,在chrome里的console我直接粘贴进去没加分号,尴尬,不过直接在node.js运行的话,就没问题
`function sleep(time) {
return new Promise(resolve => setTimeout(resolve, time))
};
const t1 = +new Date();
sleep(3000).then(() => {
const t2 = +new Date();
console.log(t2 - t1);
})`
//如果没加分号,在chrome里的报错是 Uncaught SyntaxError: Identifier 't1' has already been declared
// at :1:1
from blog.
有报错截图吗?请在 Chrome 浏览器运行或者在 node 高版本环境运行@LingZhenhua
from blog.
获取时间戳还可以 Date.now()
from blog.
哈哈,把这个竟然忘了,不错,谢谢补充~ @xanke
from blog.
貌似 +new Date 也一样可以获取的
from blog.
不带参数就是当前时间的时间戳,确实可以 @limoning
from blog.
这些玄学,写在代码里,懂的人,会心一笑,不懂得人,能懵一脸血!
from blog.
typo: '便利器接口' => '遍历器接口 (Iterator)'
from blog.
数字格式化那里可以用reduceRight,就不用reverse了。
学习到了好多新知识,感谢分享
from blog.
return obj.hasOwnProperty(typeof item + item) ?
false :
(obj[typeof item + item] = true)
这咋理解。。。
from blog.
4.4 API版的例子:
(123456789).toLocaleString('en-US') //值应该是"123,456,789"
from blog.
var a = [1, 1, '1', '2', 1]
function unique(arr) {
var res = []
for (var i = 0, len = arr.length; i < len; i++) {
var item = arr[i]
for (var j = 0,len
= res.length; j < jlen; j++) {
if (item === res[j]) //arr数组的item在res已经存在,就跳出循环
break
}
if (j === jlen) //循环完毕,arr数组的item在res找不到,就push到res数组中
res.push(item)
}
return res
}
console.log(unique(a)) // [1, 2, "1"]
3.1 第二个循环的长度变量手误了,23333
from blog.
@WittBulter 好棒 谢谢你!
from blog.
想请教下,在讲述Array.slice那节里面,“因为 ie 下的 dom 对象是以 com 对象的形式实现的,js 对象与com对象不能进行转换 ”,com对象是指什么?
from blog.
两种不同的标准,早期浏览器战争时代,各自都执行各自的标准,那时候标准都不统一。
HTML DOM 是 W3C 标准(是 HTML 文档对象模型的英文缩写,Document Object Model for HTML)。
HTML DOM 定义了用于 HTML 的一系列标准的对象,以及访问和处理 HTML 文档的标准方法。
通过 DOM,可以访问所有的 HTML 元素,连同它们所包含的文本和属性。可以对其中的内容进行修改和删除,同时也可以创建新的元素。
HTML DOM 独立于平台和编程语言。它可被任何编程语言诸如 Java、JavaScript 和 VBScript 使用。
COM组件是遵循COM规范编写、以Win32动态链接库(DLL)或可执行文件(EXE)形式发布的可执行二进制代码,能够满足对组件架构的所有需求。遵循COM的规范标准,组件与应用、组件与组件之间可以互操作,极其方便地建立可伸缩的应用系统。COM是一种技术标准,其商业品牌则称为ActiveX。
@lynxerzhang
from blog.
�toLocalString 居然不能转成大写的中文,一点都不好玩
from blog.
@jawil 感谢回复,谢谢!
from blog.
后端的人也很少写位操作运算吧,好像只有搞过算法竞赛的人才喜欢写
from blog.
from blog.
谢谢分享
from blog.
对于数字字符串转千分位的分析有些异议
function formatNumber(str) {
return str.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
console.log(formatNumber("123456789")) // 1,234,567,890
-
\B是 不是单词边界,也就是除了'1'前面的位置,1和2之间,2和3之间,3和4之间等
-
(?=(\d{3})+(?!\d))的作用就是说明,除了1之前的位置,其他字符之间的边界,后面必须跟着3N个数字直到字符串末尾,把(?!\d)换成$更好。/\B(?=(\d{3})+$)/g
from blog.
此处是否有问题,Date 实例走 ToPrimitive 优先走 toString?
from blog.
很多都很有用的,不过对于+new Date()这块一时还不是很明白。
我也不喜欢加分号,不过写交换变量的时候的确存在问题...那就把分号加前面吧...
;[a, b] = [b, a]
from blog.
github还能这样用......
from blog.
交换顺序那个,我还看到过
var a = 2,b =3; b = [a, a=b][0]
from blog.
@hua1995116 前几天好像还看到小胡子哥在知乎上写过这个?
from blog.
真的是大神
from blog.
reduce 有风险, 如果数组是空数组 [], 会爆错老哥
from blog.
总结挺到位。
from blog.
@yanche 那是因为扩展运算符会默认调用 Iterator 接口,而 arguments 原生具备 Iterator 接口
from blog.
亲嘴的那个动图咋弄出来的撒。给个调用方法。
from blog.
Related Issues (20)
- test
- question
- 学习了!
- 安利一下自己为 GitHub 开发的首个 Chrome 插件—GayHub😂 HOT 51
- CSS 黑魔法小技巧,让你少写不必要的JS,代码更优雅 HOT 47
- blog搬家了?请放出地址呦 HOT 2
- 一行代码实现一个简单的模板字符串替换 HOT 17
- 哥们你域名过期了 http://qdxmq.com/ HOT 1
- add方法里的数组有没有必要抽出一个config.js文件 HOT 1
- 3 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 #------------------------------------------------- # # Project created by QtCreator 2018-10-25T08:32:36 # #------------------------------------------------- QT += core gui QT += serialport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = COMTOOLV2 TEMPLATE = app RC_FILE =main.rc # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLS HOT 2
- a == 1 && a == 2 && a == 3 输出true方法
- 前端小蜜圈链接跳转到了菠菜站了 HOT 2
- PM2部署网站的一个诡异缓存问题
- echo 127.0.0.1
- vue项目 HOT 1
- m
- 停更了?
- 三次握手与四次挥手
- 有人继续维护吗? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.