var i = 0 Object.defineProperty(window,‘x‘,{ get(){ return ++i } }) function Fn(){ if(this.constructor == Fn){ this.id =i }else{ let obj = {} obj.__proto__ = Fn.prototype obj.id = i return obj } }
function changeStr(str = ‘hello-world-aaaa‘){ let s = ‘‘ let arr = str.split(‘-‘) for(let i = 0;i < arr.length;i++){ let item = arr[i] item = item.replace(item[0],item[0].toUpperCase()) s += item } return s }
function flat(arr = [1,2,3,[4,5,[6,7]]],deep = 0){ if(deep <= 0){ return arr } if(deep == Number.Infinity){ while(arr.some(Array.isArray)){ arr = [].concat(...arr) } return arr } while(arr.some(Array.isArray) && deep > 0){ arr = [].concat(...arr) deep-- } return arr }
原文:https://www.cnblogs.com/zhenjianyu/p/13332286.html