const interfaces = require('os').networkInterfaces()
let IPAddress = ''
for (let devName in interfaces) {
let iface = interfaces[devName]
for (let i = 0; i < iface.length; i++) {
let alias = iface[i]
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
IPAddress = alias.address
}
}
}
function scrollToSomeWhere(ele, speed){
if(!speed) speed = 300;
if(!ele){
$("html,body").animate({scrollTop:0},speed);
}else{
if(ele.length>0) $("html,body").animate({scrollTop:$(ele).offset().top - 150},speed);
}
return false;
}
$('.contactUsBtn').click(function () {
scrollToSomeWhere('#toContactUs',300)
})
lodash
中 merge
函數(shù)實現(xiàn)
function isObject (value) {
const type = typeof value
return value !== null && (type === 'object' || type === 'function')
}
function merge (source, other) {
if (!this.isObject(source) || !this.isObject(other)) {
return other === undefined ? source : other
}
// 合并兩個對象的 key,另外要區(qū)分?jǐn)?shù)組的初始值為 []
return Object.keys({...source, ...other}).reduce((acc, key) => {
// 遞歸合并 value
acc[key] = this.merge(source[key], other[key])
return acc
}, Array.isArray(source) ? [] : {})
},
js
中Object.Assign
方法的實現(xiàn)
function zyEs6AssignPolyfill() {
if (!Object.assign) {
Object.defineProperty(Object, "assign", {
enumerable: false,
configurable: true,
writable: true,
value: function (target, firstSource) {
"use strict";
if (target === undefined || target === null)
throw new TypeError("Cannot convert first argument to object");
var to = Object(target);
for (var i = 1; i < arguments.length; i++) {
var nextSource = arguments[i];
if (nextSource === undefined || nextSource === null) continue;
var keysArray = Object.keys(Object(nextSource));
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
var nextKey = keysArray[nextIndex];
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
if (desc !== undefined && desc.enumerable) to[nextKey] = nextSource[nextKey];
}
}
return to;
}
});
}
}
最后編輯于 :2020.04.28 18:28:04
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者