diveDylan / blog

My blog, detail is in the issues list
2 stars 0 forks source link

想法合集 #9

Open diveDylan opened 5 years ago

diveDylan commented 5 years ago

微信小程序相关

实现一个vscode插件右击新增组件和页面能达到微信开发工具的效果 见仓库: vs-wx-command

diveDylan commented 5 years ago

实现一个const

function myConst(obj, key, val) {
    Object.defineProperty(obj, key, { 
          value: val,
          writable: false,
         configurable: false
})
}

improve version

function myConst( key, val) {
    Object.defineProperty(window, key, { 
          value: val,
          writable: false,
         configurable: false
})
}
diveDylan commented 5 years ago

freeze

// 单层引用
const a = { name: 'dylan'}
const b = Object.assign({}, a)
const c = b
Object.freeze(b)
a.name = 'zeng'
c.age = 1
console.log(a, c)

second


// 单层引用
const a = { name: 'dylan'}
const b = Object.assign(a, {})
const c = b
Object.freeze(b)
a.name = 'zeng'
c.age = 1
console.log(a, c)

输出代码是否符合你的预期

diveDylan commented 5 years ago

url loading

const pre = '/diveDylan/blog/issues/loading'
const dot = '>'
let i = 0
function loading() {
    const url = pre + dot.repeat( i % 5 + 1)
    window.history.pushState(i, `loading`, url)
    i ++
}
setInterval(loading, 1000)