diff --git "a/Symbol.iterator \350\277\255\344\273\243\345\231\250.js" "b/Symbol.iterator \350\277\255\344\273\243\345\231\250.js" new file mode 100644 index 0000000..daa4800 --- /dev/null +++ "b/Symbol.iterator \350\277\255\344\273\243\345\231\250.js" @@ -0,0 +1,33 @@ +let obj = { + a: 1, + b: 2 +} +console.log(...obj) //Found non-callable @@iterator Object身上没有Symbol.iterator + +for(let v of obj) { + console.log(v) //同上都会报错 +} +//Array身上天生具备Symbol.iterator +let arr = [1,2,3,4]; +console.log([...arr]);//(4) [1, 2, 3, 4] +//实现一个 + +let obj2 = { + 0: 'a', + 1: 'b', + 2: 'c', + length: 3, + [Symbol.iterator]: function() { + let index = 0 + let next = () => { + return { + value: this[index], + done: this.length === index++ + } + } + return { + next + } + } +} +console.log([...obj2]) \ No newline at end of file diff --git "a/json\346\225\260\346\215\256\347\261\273\345\236\213.js" "b/json\346\225\260\346\215\256\347\261\273\345\236\213.js" new file mode 100644 index 0000000..ea8e340 --- /dev/null +++ "b/json\346\225\260\346\215\256\347\261\273\345\236\213.js" @@ -0,0 +1,30 @@ +// 两种特殊类型:数组(array)、对象(object) +// 四种基础类型:字符串(string)、数字(number)、布尔型(boolean)、NULL值 + +var obj = { + a: 1, + b:2, + c: { + cc: 20 + }, + d: [0,1,2], + f: undefined, //json中没有undefined 所以这个属性被忽略 + e: null, + g: function(){}, //同理没有function + h: /cc/ +} + +var obj2 = obj + +obj2.a = 3 +obj.c.cc = 33 +console.log(obj, obj2)//{a: 3, b: 2, c: {cc:33} {a: 3, b: 2, c: {cc:33} +obj.d[0] = 9 +console.log(obj, obj2) //[9,1,2] [9,1,2] + +var obj3 = JSON.parse(JSON.stringify(obj)) +obj3.a = 4 +obj3.c.cc = 44 +console.log(obj, obj3) //{a: 3, b: 2, c: {cc:33}} {a: 4, b: 2, c:{cc:44} } +obj3.d[1] = 99 +// [9, 1, 2] [9, 99, 2] \ No newline at end of file diff --git a/vue/vue-router/demo01/index.html b/vue/vue-router/demo01/index.html new file mode 100644 index 0000000..700aaae --- /dev/null +++ b/vue/vue-router/demo01/index.html @@ -0,0 +1,25 @@ + + + + + + + vue router + + + + go1 + go2 + go3 + go4 +
+
+ + + + + + + + + \ No newline at end of file diff --git a/vue/vue-router/demo01/index.js b/vue/vue-router/demo01/index.js new file mode 100644 index 0000000..2cf2131 --- /dev/null +++ b/vue/vue-router/demo01/index.js @@ -0,0 +1,32 @@ +// console.log(window.location.hash) +let url = window.location.hash.substring(1) +url = url || 1 +// console.log(url) +let div = document.getElementById(`div${url}`) +// console.log(div) +const app = document.getElementById('app') +console.log(app) +if (div) { + app.appendChild(div) + div.style.display = 'block' +} else { + div = document.getElementById('div404') + div.style.display = 'block' +} + +window.addEventListener('hashchange', (e) => { + console.log('hash改变了') + url = window.location.hash.substring(1) + div = document.getElementById(`div${url}`) + // console.log(app.children) + if (div) { + let oldDIv = app.children[0] + oldDIv.style.display = 'none' + document.body.appendChild(oldDIv) + app.appendChild(div) + div.style.display = 'block' + }else { + div = document.getElementById('div404') + div.style.display = 'block' + } +}) \ No newline at end of file diff --git a/vue/vue-router/demo02/index.html b/vue/vue-router/demo02/index.html new file mode 100644 index 0000000..04c34b3 --- /dev/null +++ b/vue/vue-router/demo02/index.html @@ -0,0 +1,12 @@ + + + + + + Document + + + + + + \ No newline at end of file diff --git a/vue/vue-router/demo02/index.js b/vue/vue-router/demo02/index.js new file mode 100644 index 0000000..a424c8c --- /dev/null +++ b/vue/vue-router/demo02/index.js @@ -0,0 +1,3 @@ +window.addEventListener('popstate', () => { + console.log('xxx') +}) \ No newline at end of file diff --git "a/\345\217\257\344\273\245\346\224\271\345\217\230\350\257\215\346\263\225\344\275\234\347\224\250\345\237\237\347\232\204\346\226\271\345\274\217.js" "b/\345\217\257\344\273\245\346\224\271\345\217\230\350\257\215\346\263\225\344\275\234\347\224\250\345\237\237\347\232\204\346\226\271\345\274\217.js" new file mode 100644 index 0000000..d185b0b --- /dev/null +++ "b/\345\217\257\344\273\245\346\224\271\345\217\230\350\257\215\346\263\225\344\275\234\347\224\250\345\237\237\347\232\204\346\226\271\345\274\217.js" @@ -0,0 +1,33 @@ +function c() { + console.log(a) +} +var a = 'cc' +c() // cc + +//eval + +function c() { + eval('var a = "dd"') + console.log(a) +} +var a = 'cc' +c() //dd + +//with + +var o1 = { + a: 1 +} +var o2 = { + b: 2 +} +function c(obj) { + with(obj){ + a:3 + } +} +c(o1) +console.log(o1.a) +c(o2) +console.log(o2.a) +console.log(a) \ No newline at end of file diff --git "a/\345\256\236\347\216\260\344\270\200\344\270\252\347\256\200\345\215\225\347\232\204promise.js" "b/\345\256\236\347\216\260\344\270\200\344\270\252\347\256\200\345\215\225\347\232\204promise.js" new file mode 100644 index 0000000..51d2465 --- /dev/null +++ "b/\345\256\236\347\216\260\344\270\200\344\270\252\347\256\200\345\215\225\347\232\204promise.js" @@ -0,0 +1,41 @@ +// function ccPromise(cb) { +// var that = this +// that.onResolvedCallback = [] +// function resolve(value) { +// setTimeout(() => { +// that.date = value +// that.onResolvedCallback.forEach(callback => callback(value)) +// }) +// } +// cb(resolve.bind(that)) +// } +// ccPromise.prototype.then = function(onResolved) { +// var that = this +// return new ccPromise(resolve => { +// that.onResolvedCallback.push(function() { +// var result = onResolved(that.data) +// if(result instanceof ccPromise) { +// result.then(resolve) +// } else { +// resolve(result) +// } +// }) +// }) +// } + +// new ccPromise(resolve => { +// setTimeout(() => { +// resolve(1) +// }, 500) +// }) +// .then(res => { +// console.log(res) +// return new ccPromise(resolve => { +// setTimeout(() => { +// resolve(2) +// }, 500) +// }) +// }) +// .then(console.log) + +//极简型