-
Notifications
You must be signed in to change notification settings - Fork 0
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
大杂烩 #24
Comments
|
几个样式导致 Safari (ios 自动重启): div {
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
width:10000px; height:10000px;
} |
浅拷贝和深拷贝 // 浅拷贝
var obj2 = { a: 1, b : {c: 3} }
var newObj = Object.assign({}, obj2)
console.log(newObj.b === obj2.b) // true
// 其中,obj2和newObj 的b属性是引用的同一个对象,即 b 属性的引用是一样的
// 深拷贝 使用JSON.stringify,
// 缺点: 对象的属性如果是方法的话, 则这个属性会被忽略(即这个属性不能被string化)
// Deep Clone
let obj1 = { a: 0 , b: { c: 0}, d: function() {}};
let obj3 = JSON.parse(JSON.stringify(obj1));
obj1.a = 4;
obj1.b.c = 4;
console.log(JSON.stringify(obj3)); // { a: 0, b: { c: 0}}
console.log(obj1.b === obj3.b) // false |
判断是否是原生js对象 from redux
/**
* @param {any} obj The object to inspect.
* @returns {boolean} True if the argument appears to be a plain object.
*/
function isPlainObject(obj) {
if (typeof obj !== 'object' || obj === null) return false;
var proto = obj;
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto);
}
return Object.getPrototypeOf(obj) === proto;
}
// 如果只是简单的判断是否是对象的话,可以使用;
Object.prototype.toString.call(obj) === ''[object Object]''
// 举个🌰:
var o1 = {};
function person(a, b) {
this.a = a
this.b = b
}
var o2 = new person(1,2);
var res = isPlainObject(o1)
var res2 = isPlainObject(o2)
console.log('res:', res) // false
console.log('res:', res2) // flase
// 从代码的定义可以看出,是否是原生对象,即判断这个对象最上层原型是不是就是
// Object.getPrototypeOf(obj) 拿到的原型 |
new Date 参数兼容性更好的写法http://dygraphs.com/date-formats.html // new Date('2019-04-06 17:00:00' ) 这种写法在iOS 系统上存在兼容性问
// 将 '2019-04-06 17:00:00' 使用者种有兼容性更好的写法,使用正则捕获,分别取出年月日,时分秒
// new Date(2019, 04, 06, 17, 0,0,0)
const REGEX_PARSE = /^(\d{4})-?(\d{1,2})-?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d{1,3})? $/
const d = dateStr.match(REGEX_PARSE);
const data = new Date(d[1], d[2] - 1, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, d[7] || 0)
// 取出来的值时字符串,但是转换过程中,会把年月日,时分秒转换成Number 类型 |
RFC822 or ISO 8601 date |
日期处理相关https://github.com/you-dont-need/You-Dont-Need-Momentjs#quick-links 获取 UTC 时间戳new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000; |
new Function 笔记
let func = new Function ([arg1, arg2, ...argN], functionBody); 可以有下面三种等价的写法 new Function('a', 'b', 'return a + b'); // basic syntax
new Function('a,b', 'return a + b'); // comma-separated
new Function('a , b', 'return a + b'); // comma-separated with spaces
function getFunc() {
let value = "test";
console.log('this", this) // => 返回全局变量,在浏览器里,this 就是window
let func = new Function('alert(value)');
return func;
}
getFunc()(); // error: value is not defined |
js 生成 GUIID |
一键开启 macOS HiDPI
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
记录一些生活中遇到的问题和解决方案,或者一些有用的积累:
原因: 网络供应商劫持了DNS, 注入了广告
解决办法:
知乎:公共DNS哪家强?
国内部分网络运营商需要配置DNS
Mac :修改 DNS 及清除 DNS 缓存
路由器设置DNS
114官网
The text was updated successfully, but these errors were encountered: