├── main ├── src │ ├── topic │ │ ├── promise.ts │ │ ├── webworker.ts │ │ ├── iterator.ts │ │ ├── microtasks.ts │ │ └── eventLoop.ts │ ├── vite-env.d.ts │ ├── main.ts │ ├── assets │ │ └── vue.svg │ ├── App.vue │ ├── components │ │ └── HelloWorld.vue │ └── style.css ├── .vscode │ └── extensions.json ├── vite.config.ts ├── tsconfig.node.json ├── .gitignore ├── package.json ├── index.html ├── tsconfig.json ├── public │ └── vite.svg └── README.md ├── docs ├── per │ └── index.md ├── safe │ └── index.md ├── network │ ├── 5.md │ ├── 9.md │ ├── 3.md │ ├── 8.md │ ├── 4.md │ ├── 7.md │ ├── 6.md │ ├── 2.md │ └── index.md ├── .vuepress │ ├── theme │ │ ├── noopModule.js │ │ ├── styles │ │ │ ├── config.styl │ │ │ ├── toc.styl │ │ │ ├── wrapper.styl │ │ │ ├── arrow.styl │ │ │ ├── mobile.styl │ │ │ └── custom-blocks.styl │ │ ├── README.md │ │ ├── layouts │ │ │ └── 404.vue │ │ ├── components │ │ │ ├── Page.vue │ │ │ ├── DropdownTransition.vue │ │ │ ├── SidebarButton.vue │ │ │ ├── SubMainCard.vue │ │ │ ├── TopBanner.vue │ │ │ ├── ThirdCard.vue │ │ │ ├── Sidebar.vue │ │ │ ├── Footer.vue │ │ │ ├── NavLink.vue │ │ │ └── MainCard.vue │ │ ├── global-components │ │ │ └── Badge.vue │ │ ├── LICENSE │ │ ├── index.js │ │ └── package.json │ ├── styles │ │ ├── index.styl │ │ └── palette.styl │ ├── enhanceApp.js │ └── components │ │ └── GhongZhongHao.vue ├── compiler │ └── index.md ├── unknow.md ├── design │ └── index.md ├── vue │ ├── vue-2.6.0 │ │ ├── src │ │ │ ├── platforms │ │ │ │ ├── weex │ │ │ │ │ ├── runtime │ │ │ │ │ │ ├── directives │ │ │ │ │ │ │ └── index.js │ │ │ │ │ │ ├── text-node.js │ │ │ │ │ │ ├── components │ │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ │ ├── transition.js │ │ │ │ │ │ │ └── richtext.js │ │ │ │ │ │ ├── modules │ │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ │ ├── attrs.js │ │ │ │ │ │ │ ├── events.js │ │ │ │ │ │ │ ├── class.js │ │ │ │ │ │ │ └── style.js │ │ │ │ │ │ ├── patch.js │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ └── recycle-list │ │ │ │ │ │ │ └── render-component-template.js │ │ │ │ │ ├── compiler │ │ │ │ │ │ ├── directives │ │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ │ └── model.js │ │ │ │ │ │ ├── modules │ │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ │ ├── recycle-list │ │ │ │ │ │ │ │ ├── component-root.js │ │ │ │ │ │ │ │ ├── v-once.js │ │ │ │ │ │ │ │ ├── component.js │ │ │ │ │ │ │ │ ├── text.js │ │ │ │ │ │ │ │ ├── v-bind.js │ │ │ │ │ │ │ │ ├── v-on.js │ │ │ │ │ │ │ │ ├── v-for.js │ │ │ │ │ │ │ │ ├── recycle-list.js │ │ │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ │ │ └── v-if.js │ │ │ │ │ │ │ ├── append.js │ │ │ │ │ │ │ ├── props.js │ │ │ │ │ │ │ └── class.js │ │ │ │ │ │ └── index.js │ │ │ │ │ ├── entry-compiler.js │ │ │ │ │ ├── entry-runtime-factory.js │ │ │ │ │ └── util │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ ├── element.js │ │ │ │ │ │ └── parser.js │ │ │ │ └── web │ │ │ │ │ ├── entry-runtime.js │ │ │ │ │ ├── runtime │ │ │ │ │ ├── directives │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ └── show.js │ │ │ │ │ ├── components │ │ │ │ │ │ └── index.js │ │ │ │ │ ├── modules │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ └── class.js │ │ │ │ │ ├── patch.js │ │ │ │ │ ├── class-util.js │ │ │ │ │ ├── node-ops.js │ │ │ │ │ └── index.js │ │ │ │ │ ├── server │ │ │ │ │ ├── directives │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ ├── show.js │ │ │ │ │ │ └── model.js │ │ │ │ │ ├── modules │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ ├── class.js │ │ │ │ │ │ ├── style.js │ │ │ │ │ │ ├── dom-props.js │ │ │ │ │ │ └── attrs.js │ │ │ │ │ └── compiler.js │ │ │ │ │ ├── compiler │ │ │ │ │ ├── directives │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ ├── html.js │ │ │ │ │ │ └── text.js │ │ │ │ │ ├── modules │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ ├── class.js │ │ │ │ │ │ └── style.js │ │ │ │ │ ├── index.js │ │ │ │ │ ├── options.js │ │ │ │ │ └── util.js │ │ │ │ │ ├── entry-compiler.js │ │ │ │ │ ├── entry-server-basic-renderer.js │ │ │ │ │ ├── util │ │ │ │ │ ├── index.js │ │ │ │ │ ├── compat.js │ │ │ │ │ ├── attrs.js │ │ │ │ │ ├── style.js │ │ │ │ │ └── class.js │ │ │ │ │ └── entry-server-renderer.js │ │ │ ├── core │ │ │ │ ├── components │ │ │ │ │ └── index.js │ │ │ │ ├── vdom │ │ │ │ │ ├── modules │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ └── ref.js │ │ │ │ │ └── helpers │ │ │ │ │ │ ├── is-async-placeholder.js │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ ├── get-first-component-child.js │ │ │ │ │ │ ├── merge-hook.js │ │ │ │ │ │ └── extract-props.js │ │ │ │ ├── global-api │ │ │ │ │ ├── mixin.js │ │ │ │ │ ├── use.js │ │ │ │ │ ├── assets.js │ │ │ │ │ └── index.js │ │ │ │ ├── util │ │ │ │ │ ├── index.js │ │ │ │ │ ├── perf.js │ │ │ │ │ └── lang.js │ │ │ │ ├── instance │ │ │ │ │ ├── render-helpers │ │ │ │ │ │ ├── resolve-filter.js │ │ │ │ │ │ ├── bind-object-listeners.js │ │ │ │ │ │ ├── resolve-scoped-slots.js │ │ │ │ │ │ ├── render-slot.js │ │ │ │ │ │ ├── check-keycodes.js │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ ├── bind-dynamic-keys.js │ │ │ │ │ │ ├── render-list.js │ │ │ │ │ │ ├── resolve-slots.js │ │ │ │ │ │ ├── render-static.js │ │ │ │ │ │ └── bind-object-props.js │ │ │ │ │ ├── index.js │ │ │ │ │ └── inject.js │ │ │ │ ├── index.js │ │ │ │ └── observer │ │ │ │ │ ├── traverse.js │ │ │ │ │ ├── array.js │ │ │ │ │ └── dep.js │ │ │ ├── compiler │ │ │ │ ├── directives │ │ │ │ │ ├── index.js │ │ │ │ │ ├── bind.js │ │ │ │ │ └── on.js │ │ │ │ ├── parser │ │ │ │ │ ├── entity-decoder.js │ │ │ │ │ └── text-parser.js │ │ │ │ ├── index.js │ │ │ │ ├── codeframe.js │ │ │ │ └── create-compiler.js │ │ │ ├── shared │ │ │ │ └── constants.js │ │ │ └── server │ │ │ │ ├── util.js │ │ │ │ ├── optimizing-compiler │ │ │ │ └── index.js │ │ │ │ ├── create-basic-renderer.js │ │ │ │ ├── webpack-plugin │ │ │ │ ├── util.js │ │ │ │ ├── server.js │ │ │ │ └── client.js │ │ │ │ ├── template-renderer │ │ │ │ ├── parse-template.js │ │ │ │ ├── create-async-file-mapper.js │ │ │ │ └── template-stream.js │ │ │ │ ├── bundle-renderer │ │ │ │ └── source-map-support.js │ │ │ │ └── write.js │ │ ├── types │ │ │ ├── plugin.d.ts │ │ │ ├── index.d.ts │ │ │ ├── umd.d.ts │ │ │ └── vnode.d.ts │ │ └── LICENSE │ ├── 1.md │ └── index.md ├── work │ └── index.md ├── node │ └── index.md ├── js │ ├── 5.md │ ├── 2.md │ ├── 7.md │ ├── 3.md │ ├── 1.md │ └── 6.md ├── borswer │ └── index.md ├── webpack │ └── index.md ├── about.md ├── noop │ └── index.md ├── css │ └── index.md └── dsa │ └── index.md ├── scripts └── build.sh ├── .gitattributes ├── src └── js │ ├── 3.js │ ├── this.js │ ├── eventloop.html │ └── 1-5.js ├── deploy.sh ├── question.md ├── LICENSE ├── package.json └── .gitignore /main/src/topic/promise.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /main/src/topic/webworker.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/per/index.md: -------------------------------------------------------------------------------- 1 | # 性能优化相关面试题 2 | -------------------------------------------------------------------------------- /docs/safe/index.md: -------------------------------------------------------------------------------- 1 | # 前端开发中的安全问题 2 | -------------------------------------------------------------------------------- /docs/network/5.md: -------------------------------------------------------------------------------- 1 | # 5.从输入一个url到呈现网页,都有哪些步骤 -------------------------------------------------------------------------------- /docs/network/9.md: -------------------------------------------------------------------------------- 1 | # axios 是如何实现的 2 | 3 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/noopModule.js: -------------------------------------------------------------------------------- 1 | export default {} 2 | -------------------------------------------------------------------------------- /docs/compiler/index.md: -------------------------------------------------------------------------------- 1 | # 编译器 2 | 3 | - ES6 代码转成 ES5 代码的实现思路是什么 -------------------------------------------------------------------------------- /docs/network/3.md: -------------------------------------------------------------------------------- 1 | # 3.为什么通常在发送数据埋点请求的时候使用的是 1x1 像素的透明 gif 图片? -------------------------------------------------------------------------------- /docs/unknow.md: -------------------------------------------------------------------------------- 1 | [BFF层](https://www.jianshu.com/p/eb1875c62ad3) -------------------------------------------------------------------------------- /docs/design/index.md: -------------------------------------------------------------------------------- 1 | # 设计 2 | 3 | - 介绍下观察者模式和订阅-发布模式的区别,各自适用于什么场景 -------------------------------------------------------------------------------- /main/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/config.styl: -------------------------------------------------------------------------------- 1 | $contentClass = '.theme-default-content' 2 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/runtime/directives/index.js: -------------------------------------------------------------------------------- 1 | export default { 2 | } 3 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/toc.styl: -------------------------------------------------------------------------------- 1 | .table-of-contents 2 | .badge 3 | vertical-align middle 4 | -------------------------------------------------------------------------------- /docs/network/8.md: -------------------------------------------------------------------------------- 1 | # 8.谈谈你对 HTTP2 的理解 2 | 3 | 相关面试题: 4 | 5 | - 简单讲解一下http2的多路复用 6 | - 对http2有哪些了解 7 | -------------------------------------------------------------------------------- /docs/network/4.md: -------------------------------------------------------------------------------- 1 | # 4.谈谈你对TCP的理解 2 | 3 | 相关题目: 4 | - 三次握手和四次挥手的理解 5 | - A、B 机器正常连接后,B 机器突然重启,问 A 此时处于 TCP 什么状态 -------------------------------------------------------------------------------- /main/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"] 3 | } 4 | -------------------------------------------------------------------------------- /docs/work/index.md: -------------------------------------------------------------------------------- 1 | # 工作中的一些问题 2 | 3 | - 对之前的项目做过什么优化,讲一讲 4 | - 对之前的项目遇到过什么难点,讲一讲 5 | - 项目中的难点和亮点 6 | - 你做过的一个项目,还能有什么优化吗? -------------------------------------------------------------------------------- /docs/node/index.md: -------------------------------------------------------------------------------- 1 | # node 常考题 2 | 3 | - 说说浏览器和 Node 事件循环的区别 4 | - EventLoop的理解 5 | - 浏览器渲染触发在EventLoop的哪个阶段,触发机制是怎么样的 6 | - node中的垃圾收集机制 -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/components/index.js: -------------------------------------------------------------------------------- 1 | import KeepAlive from './keep-alive' 2 | 3 | export default { 4 | KeepAlive 5 | } 6 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/entry-runtime.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import Vue from './runtime/index' 4 | 5 | export default Vue 6 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/directives/index.js: -------------------------------------------------------------------------------- 1 | import model from './model' 2 | 3 | export default { 4 | model 5 | } 6 | -------------------------------------------------------------------------------- /docs/js/5.md: -------------------------------------------------------------------------------- 1 | # 生成器 Generator 2 | 3 | 4 | 5 | ### 参考 6 | 7 | - [MDN yield](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/yield) -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/entry-compiler.js: -------------------------------------------------------------------------------- 1 | export { compile } from 'weex/compiler/index' 2 | export { generateCodeFrame } from 'compiler/codeframe' 3 | -------------------------------------------------------------------------------- /docs/borswer/index.md: -------------------------------------------------------------------------------- 1 | # 浏览器相关的知识点 2 | 3 | - 对浏览器渲染机制的理解(具体到细节,从渲染树到paint之间究竟发生了什么) 4 | - 浏览器的架构,bom,dom 5 | - cookie,session,localstorage 区别 6 | - 浏览器内核有哪些 7 | - 什么是CDN,页面怎么优化 -------------------------------------------------------------------------------- /docs/webpack/index.md: -------------------------------------------------------------------------------- 1 | # 前端构建 2 | 3 | - 介绍下 webpack 热更新原理,是如何做到在不刷新浏览器的前提下更新页面的 4 | - Tree shaking的实现原理 5 | - 谈谈对webpack的理解,常用哪些plugin,对webpack配置是否了解,对项目打包是否做过什么优化 6 | - 代码规范如何做 -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/vdom/modules/index.js: -------------------------------------------------------------------------------- 1 | import directives from './directives' 2 | import ref from './ref' 3 | 4 | export default [ 5 | ref, 6 | directives 7 | ] 8 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/runtime/directives/index.js: -------------------------------------------------------------------------------- 1 | import model from './model' 2 | import show from './show' 3 | 4 | export default { 5 | model, 6 | show 7 | } 8 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/server/directives/index.js: -------------------------------------------------------------------------------- 1 | import show from './show' 2 | import model from './model' 3 | 4 | export default { 5 | show, 6 | model 7 | } 8 | -------------------------------------------------------------------------------- /docs/network/7.md: -------------------------------------------------------------------------------- 1 | # 7.谈谈你对 https 的理解 2 | 3 | ## 相关面试题 4 | - 介绍下 HTTPS 中间人攻击 5 | - HTTPS 握手过程中,客户端如何验证证书的合法性 6 | - 介绍 HTTPS 握手过程 7 | - https 建立连接的过程及通信 如何劫持,鉴别是否被劫持 8 | - 对https的理解,对称、非对称加密在哪部使用 9 | -------------------------------------------------------------------------------- /docs/.vuepress/styles/index.styl: -------------------------------------------------------------------------------- 1 | /** 2 | * Custom Styles here. 3 | * 4 | * ref:https://v1.vuepress.vuejs.org/config/#index-styl 5 | */ 6 | 7 | .home .hero img 8 | max-width 450px!important 9 | -------------------------------------------------------------------------------- /docs/network/6.md: -------------------------------------------------------------------------------- 1 | # 6.谈谈你对 HTTP 的理解,状态码的含义,header 定义 2 | 3 | 相关面试题 4 | - http的头部有什么字段,简要描述(缓存,content-type,cookie等等) 5 | - http keep—alive都解决了哪些问题 keep-alive是从c - nginx建立的还是直接到服务建立的长连接,与websocket有什么区别与联系 -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | export PATH=$NODEJS_12_16_1_BIN:$YARN_1_22_4_BIN:$PATH 2 | 3 | echo "node: $(node -v)" 4 | echo "npm: v$(npm -v)" 5 | 6 | NODE_ENV=development npm install 7 | 8 | npm run build 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.css linguist-language=javascript 2 | *.less linguist-language=javascript 3 | *.js linguist-language=javascript 4 | *.html linguist-language=javascript 5 | *.sh linguist-language=javascript -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/vdom/helpers/is-async-placeholder.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export function isAsyncPlaceholder (node: VNode): boolean { 4 | return node.isComment && node.asyncFactory 5 | } 6 | -------------------------------------------------------------------------------- /main/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import vue from '@vitejs/plugin-vue' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [vue()], 7 | }) 8 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/runtime/components/index.js: -------------------------------------------------------------------------------- 1 | import Transition from './transition' 2 | import TransitionGroup from './transition-group' 3 | 4 | export default { 5 | Transition, 6 | TransitionGroup 7 | } 8 | -------------------------------------------------------------------------------- /docs/vue/1.md: -------------------------------------------------------------------------------- 1 | # nextTick 2 | 3 | 源码,其实就是一个微任务,下一个周期: 4 | 5 | ```js 6 | function nextTick(fn) { 7 | const p = currentFlushPromise || resolvedPromise; 8 | return fn ? p.then(this ? fn.bind(this) : fn) : p; 9 | } 10 | ``` -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/compiler/directives/index.js: -------------------------------------------------------------------------------- 1 | import model from './model' 2 | import text from './text' 3 | import html from './html' 4 | 5 | export default { 6 | model, 7 | text, 8 | html 9 | } 10 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/compiler/modules/index.js: -------------------------------------------------------------------------------- 1 | import klass from './class' 2 | import style from './style' 3 | import model from './model' 4 | 5 | export default [ 6 | klass, 7 | style, 8 | model 9 | ] 10 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/compiler/directives/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import on from './on' 4 | import bind from './bind' 5 | import { noop } from 'shared/util' 6 | 7 | export default { 8 | on, 9 | bind, 10 | cloak: noop 11 | } 12 | -------------------------------------------------------------------------------- /main/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "ESNext", 5 | "moduleResolution": "Node", 6 | "allowSyntheticDefaultImports": true 7 | }, 8 | "include": ["vite.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/wrapper.styl: -------------------------------------------------------------------------------- 1 | $wrapper 2 | max-width $contentWidth 3 | margin 0 auto 4 | padding 2rem 2.5rem 5 | @media (max-width: $MQNarrow) 6 | padding 2rem 7 | @media (max-width: $MQMobileNarrow) 8 | padding 1.5rem 9 | 10 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/entry-runtime-factory.js: -------------------------------------------------------------------------------- 1 | // this entry is built and wrapped with a factory function 2 | // used to generate a fresh copy of Vue for every Weex instance. 3 | 4 | import Vue from './runtime/index' 5 | 6 | exports.Vue = Vue 7 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/types/plugin.d.ts: -------------------------------------------------------------------------------- 1 | import { Vue as _Vue } from "./vue"; 2 | 3 | export type PluginFunction = (Vue: typeof _Vue, options?: T) => void; 4 | 5 | export interface PluginObject { 6 | install: PluginFunction; 7 | [key: string]: any; 8 | } 9 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/runtime/text-node.js: -------------------------------------------------------------------------------- 1 | let latestNodeId = 1 2 | 3 | export default function TextNode (text) { 4 | this.instanceId = '' 5 | this.nodeId = latestNodeId++ 6 | this.parentNode = null 7 | this.nodeType = 3 8 | this.text = text 9 | } 10 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/server/modules/index.js: -------------------------------------------------------------------------------- 1 | import attrs from './attrs' 2 | import domProps from './dom-props' 3 | import klass from './class' 4 | import style from './style' 5 | 6 | export default [ 7 | attrs, 8 | domProps, 9 | klass, 10 | style 11 | ] 12 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/compiler/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { baseOptions } from './options' 4 | import { createCompiler } from 'compiler/index' 5 | 6 | const { compile, compileToFunctions } = createCompiler(baseOptions) 7 | 8 | export { compile, compileToFunctions } 9 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/runtime/components/index.js: -------------------------------------------------------------------------------- 1 | import Richtext from './richtext' 2 | import Transition from './transition' 3 | import TransitionGroup from './transition-group' 4 | 5 | export default { 6 | Richtext, 7 | Transition, 8 | TransitionGroup 9 | } 10 | -------------------------------------------------------------------------------- /docs/network/2.md: -------------------------------------------------------------------------------- 1 | # 2.工作中是否遇到过跨域?什么是跨域?如何解决? 2 | 3 | 4 | 5 | 相似问题: 6 | - 跨域请求可以携带cookie吗 7 | - 跨域的解决办法,jsonp的实现原理 8 | - cookie 跨域的处理方案 9 | - cookie 种在子域下能否携带发送到服务端(SSO登录) 10 | - cookie跨域服务端需要如何适配(CORS头) 11 | - 跨域的解决办法 12 | - cookie 和 token 都存放在 header 中,为什么不会劫持 token? 13 | - 一个请求跨域是否会抵达服务端 -------------------------------------------------------------------------------- /docs/.vuepress/styles/palette.styl: -------------------------------------------------------------------------------- 1 | /** 2 | * Custom palette here. 3 | * 4 | * ref:https://v1.vuepress.vuejs.org/zh/config/#palette-styl 5 | */ 6 | 7 | $accentColor = #409EFF 8 | $textColor = #222 9 | $borderColor = #f5f5f5 10 | $codeBgColor = #282c34 11 | 12 | $homePageWidth = 1280px 13 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/compiler/parser/entity-decoder.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | let decoder 4 | 5 | export default { 6 | decode (html: string): string { 7 | decoder = decoder || document.createElement('div') 8 | decoder.innerHTML = html 9 | return decoder.textContent 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/compiler/directives/html.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addProp } from 'compiler/helpers' 4 | 5 | export default function html (el: ASTElement, dir: ASTDirective) { 6 | if (dir.value) { 7 | addProp(el, 'innerHTML', `_s(${dir.value})`, dir) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/global-api/mixin.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { mergeOptions } from '../util/index' 4 | 5 | export function initMixin (Vue: GlobalAPI) { 6 | Vue.mixin = function (mixin: Object) { 7 | this.options = mergeOptions(this.options, mixin) 8 | return this 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/compiler/directives/text.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addProp } from 'compiler/helpers' 4 | 5 | export default function text (el: ASTElement, dir: ASTDirective) { 6 | if (dir.value) { 7 | addProp(el, 'textContent', `_s(${dir.value})`, dir) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/entry-compiler.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export { parseComponent } from 'sfc/parser' 4 | export { compile, compileToFunctions } from './compiler/index' 5 | export { ssrCompile, ssrCompileToFunctions } from './server/compiler' 6 | export { generateCodeFrame } from 'compiler/codeframe' 7 | -------------------------------------------------------------------------------- /docs/about.md: -------------------------------------------------------------------------------- 1 | ## 关于本站 2 | 3 | BAT代表着国内顶尖的互联网公司,包括百度、阿里、腾讯。随着这几年互联网公司不断崛起,涌现出了更多类似BAT这样的公司,成为这些公司的员工是每个前端程序员的奋斗目标。各大公司面试题层出不穷,即使你能力比较强,也可能在面试过程中失利。本站通过收集各大厂前端面试题,并对其进行深入剖析,拆解知识点,以了解顶尖互联网公司对顶尖人才的要求,最终希望你能够顺利拿到满意的 offer。 4 | 5 | 作者目前就职于百度,毒舌程序员,擅长 iOS 与前端,正在写 [前端小课](https://lefex.gitee.io/),帮助10W人入门并进阶前端,并运营公众号素燕。 6 | 7 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/runtime/components/transition.js: -------------------------------------------------------------------------------- 1 | // reuse same transition component logic from web 2 | export { 3 | transitionProps, 4 | extractTransitionData 5 | } from 'web/runtime/components/transition' 6 | 7 | import Transition from 'web/runtime/components/transition' 8 | 9 | export default Transition 10 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/runtime/modules/index.js: -------------------------------------------------------------------------------- 1 | import attrs from './attrs' 2 | import klass from './class' 3 | import events from './events' 4 | import style from './style' 5 | import transition from './transition' 6 | 7 | export default [ 8 | attrs, 9 | klass, 10 | events, 11 | style, 12 | transition 13 | ] 14 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/util/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export * from 'shared/util' 4 | export * from './lang' 5 | export * from './env' 6 | export * from './options' 7 | export * from './debug' 8 | export * from './props' 9 | export * from './error' 10 | export * from './next-tick' 11 | export { defineReactive } from '../observer/index' 12 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/modules/index.js: -------------------------------------------------------------------------------- 1 | import klass from './class' 2 | import style from './style' 3 | import props from './props' 4 | import append from './append' 5 | import recycleList from './recycle-list/index' 6 | 7 | export default [ 8 | recycleList, 9 | klass, 10 | style, 11 | props, 12 | append 13 | ] 14 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/instance/render-helpers/resolve-filter.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { identity, resolveAsset } from 'core/util/index' 4 | 5 | /** 6 | * Runtime helper for resolving filters 7 | */ 8 | export function resolveFilter (id: string): Function { 9 | return resolveAsset(this.$options, 'filters', id, true) || identity 10 | } 11 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/vdom/helpers/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export * from './merge-hook' 4 | export * from './extract-props' 5 | export * from './update-listeners' 6 | export * from './normalize-children' 7 | export * from './resolve-async-component' 8 | export * from './get-first-component-child' 9 | export * from './is-async-placeholder' 10 | -------------------------------------------------------------------------------- /docs/js/2.md: -------------------------------------------------------------------------------- 1 | # 第 2 题:async/await 2 | 3 | ES8 增加了两个关键字 async 和 await,用来解决异步编程问题,可以使用同步的代码实现异步编程。 4 | 5 | 6 | ```js 7 | (async () => { 8 | var a = await A(); 9 | var b = await B(a); 10 | var c = await C(b); 11 | var d = await D(c); 12 | })(); 13 | ``` 14 | 15 | 16 | 17 | ### 相关面试题 18 | 19 | - Async/Await 如何通过同步的方式实现异步 20 | - setTimeout、Promise、Async/Await 的区别 -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/server/compiler.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { baseOptions } from '../compiler/options' 4 | import { createCompiler } from 'server/optimizing-compiler/index' 5 | 6 | const { compile, compileToFunctions } = createCompiler(baseOptions) 7 | 8 | export { 9 | compile as ssrCompile, 10 | compileToFunctions as ssrCompileToFunctions 11 | } 12 | -------------------------------------------------------------------------------- /main/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /main/src/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import './style.css' 3 | import App from './App.vue' 4 | import { runMicrotasks } from './topic/microtasks' 5 | import { runAsyncAwait } from './topic/async_await'; 6 | import {runIterator} from './topic/iterator'; 7 | 8 | createApp(App).mount('#app') 9 | 10 | // runMicrotasks(); 11 | // runAsyncAwait(); 12 | runIterator(); 13 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/server/modules/class.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { escape } from '../util' 4 | import { genClassForVnode } from 'web/util/index' 5 | 6 | export default function renderClass (node: VNodeWithData): ?string { 7 | const classList = genClassForVnode(node) 8 | if (classList !== '') { 9 | return ` class="${escape(classList)}"` 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/runtime/modules/index.js: -------------------------------------------------------------------------------- 1 | import attrs from './attrs' 2 | import klass from './class' 3 | import events from './events' 4 | import domProps from './dom-props' 5 | import style from './style' 6 | import transition from './transition' 7 | 8 | export default [ 9 | attrs, 10 | klass, 11 | events, 12 | domProps, 13 | style, 14 | transition 15 | ] 16 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/compiler/directives/bind.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export default function bind (el: ASTElement, dir: ASTDirective) { 4 | el.wrapData = (code: string) => { 5 | return `_b(${code},'${el.tag}',${dir.value},${ 6 | dir.modifiers && dir.modifiers.prop ? 'true' : 'false' 7 | }${ 8 | dir.modifiers && dir.modifiers.sync ? ',true' : '' 9 | })` 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/compiler/directives/on.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { warn } from 'core/util/index' 4 | 5 | export default function on (el: ASTElement, dir: ASTDirective) { 6 | if (process.env.NODE_ENV !== 'production' && dir.modifiers) { 7 | warn(`v-on without argument does not support modifiers.`) 8 | } 9 | el.wrapListeners = (code: string) => `_g(${code},${dir.value})` 10 | } 11 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/server/directives/show.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export default function show (node: VNodeWithData, dir: VNodeDirective) { 4 | if (!dir.value) { 5 | const style: any = node.data.style || (node.data.style = {}) 6 | if (Array.isArray(style)) { 7 | style.push({ display: 'none' }) 8 | } else { 9 | style.display = 'none' 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/entry-server-basic-renderer.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import modules from './server/modules/index' 4 | import directives from './server/directives/index' 5 | import { isUnaryTag, canBeLeftOpenTag } from './compiler/util' 6 | import { createBasicRenderer } from 'server/create-basic-renderer' 7 | 8 | export default createBasicRenderer({ 9 | modules, 10 | directives, 11 | isUnaryTag, 12 | canBeLeftOpenTag 13 | }) 14 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/modules/recycle-list/component-root.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addAttr } from 'compiler/helpers' 4 | 5 | // mark component root nodes as 6 | export function postTransformComponentRoot (el: ASTElement) { 7 | if (!el.parent) { 8 | // component root 9 | addAttr(el, '@isComponentRoot', 'true') 10 | addAttr(el, '@templateId', '_uid') 11 | addAttr(el, '@componentProps', '$props || {}') 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /main/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "main", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vue-tsc && vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "vue": "^3.2.45" 13 | }, 14 | "devDependencies": { 15 | "@vitejs/plugin-vue": "^4.0.0", 16 | "typescript": "^4.9.3", 17 | "vite": "^4.1.0", 18 | "vue-tsc": "^1.0.24" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /docs/noop/index.md: -------------------------------------------------------------------------------- 1 | # 杂七杂八的面试题 2 | 3 | - 实现模糊搜索结果的关键词高亮显示 4 | - 在输入框中如何判断输入的是一个正确的网址。 5 | - input 搜索如何防抖,如何处理中文输入 6 | - 如何设计实现无缝轮播 7 | - 介绍下如何实现 token 加密 8 | - 浏览器缓存读取规则 9 | - 介绍下 npm 模块安装机制,为什么输入 npm install 就可以自动安装对应的模块? 10 | - 对代码构建上线流程是否了解,说一下如果让你实现的思路 11 | - JSONpatth 了解吗 12 | - 单点登录成熟的方案 13 | - jQuery 的特点,和现代框架的区别 14 | - script标签为什么要放在页面的底部 15 | - 如果script标签放在head标签中,如何让js脚本等待DOM加载完成执行 16 | - 异步加载一段JavaScript代码,如何监听这段代码是否加载完毕 17 | - 不同子域之间如何共享一段js脚本 18 | - 如何在页面上按需加载一个模块,比如点击按钮加载 -------------------------------------------------------------------------------- /main/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Vite + Vue + TS 9 | 10 | 11 | 12 |
13 |
14 |
点击
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/shared/constants.js: -------------------------------------------------------------------------------- 1 | export const SSR_ATTR = 'data-server-rendered' 2 | 3 | export const ASSET_TYPES = [ 4 | 'component', 5 | 'directive', 6 | 'filter' 7 | ] 8 | 9 | export const LIFECYCLE_HOOKS = [ 10 | 'beforeCreate', 11 | 'created', 12 | 'beforeMount', 13 | 'mounted', 14 | 'beforeUpdate', 15 | 'updated', 16 | 'beforeDestroy', 17 | 'destroyed', 18 | 'activated', 19 | 'deactivated', 20 | 'errorCaptured', 21 | 'serverPrefetch' 22 | ] 23 | -------------------------------------------------------------------------------- /main/src/assets/vue.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/js/3.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author 公众号素燕 3 | * @description 第3题:事件循环 4 | * @site 网站:https://lefex.github.io/bat/ 5 | * @xiaoke 前端小课,帮助10W人入门并进阶前端 6 | */ 7 | 8 | // 事件循环 9 | function eventLoop() { 10 | var eventLoop = []; 11 | var event; 12 | while(true) { 13 | if (eventLoop.length > 0) { 14 | event = eventLoop.shift(); 15 | 16 | try { 17 | event(); 18 | } catch (e) { 19 | 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/vdom/helpers/get-first-component-child.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { isDef } from 'shared/util' 4 | import { isAsyncPlaceholder } from './is-async-placeholder' 5 | 6 | export function getFirstComponentChild (children: ?Array): ?VNode { 7 | if (Array.isArray(children)) { 8 | for (let i = 0; i < children.length; i++) { 9 | const c = children[i] 10 | if (isDef(c) && (isDef(c.componentOptions) || isAsyncPlaceholder(c))) { 11 | return c 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/runtime/patch.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import * as nodeOps from 'web/runtime/node-ops' 4 | import { createPatchFunction } from 'core/vdom/patch' 5 | import baseModules from 'core/vdom/modules/index' 6 | import platformModules from 'web/runtime/modules/index' 7 | 8 | // the directive module should be applied last, after all 9 | // built-in modules have been applied. 10 | const modules = platformModules.concat(baseModules) 11 | 12 | export const patch: Function = createPatchFunction({ nodeOps, modules }) 13 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/README.md: -------------------------------------------------------------------------------- 1 | # @vuepress/theme-default 2 | 3 | > theme-default for VuePress 4 | 5 | ## Plugins 6 | 7 | The default theme has the following plugin built in: 8 | 9 | - [@vuepress/plugin-active-header-links](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-active-header-links) 10 | - [@vuepress/plugin-google-analytics](https://github.com/vuejs/vuepress/tree/master/packages/%40vuepress/plugin-google-analytics) 11 | - [@vuepress/plugin-search](https://github.com/vuejs/vuepress/tree/master/packages/%40vuepress/plugin-search) 12 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/modules/recycle-list/v-once.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers' 4 | 5 | function containVOnce (el: ASTElement): boolean { 6 | for (const attr in el.attrsMap) { 7 | if (/^v\-once$/i.test(attr)) { 8 | return true 9 | } 10 | } 11 | return false 12 | } 13 | 14 | export function preTransformVOnce (el: ASTElement) { 15 | if (containVOnce(el)) { 16 | getAndRemoveAttr(el, 'v-once', true) 17 | addRawAttr(el, '[[once]]', true) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /main/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "moduleResolution": "Node", 7 | "strict": true, 8 | "jsx": "preserve", 9 | "resolveJsonModule": true, 10 | "isolatedModules": true, 11 | "esModuleInterop": true, 12 | "lib": ["ESNext", "DOM"], 13 | "skipLibCheck": true, 14 | "noEmit": true 15 | }, 16 | "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], 17 | "references": [{ "path": "./tsconfig.node.json" }] 18 | } 19 | -------------------------------------------------------------------------------- /docs/.vuepress/enhanceApp.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Client app enhancement file. 3 | * 4 | * https://v1.vuepress.vuejs.org/guide/basic-config.html#app-level-enhancements 5 | */ 6 | 7 | import ElementUI from 'element-ui'; 8 | import 'element-ui/lib/theme-chalk/index.css' 9 | 10 | export default ({ 11 | Vue, // the version of Vue being used in the VuePress app 12 | options, // the options for the root Vue instance 13 | router, // the router instance for the app 14 | siteData // site metadata 15 | }) => { 16 | // ...apply enhancements for the site. 17 | Vue.use(ElementUI); 18 | }; 19 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/runtime/patch.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import * as nodeOps from 'weex/runtime/node-ops' 4 | import { createPatchFunction } from 'core/vdom/patch' 5 | import baseModules from 'core/vdom/modules/index' 6 | import platformModules from 'weex/runtime/modules/index' 7 | 8 | // the directive module should be applied last, after all 9 | // built-in modules have been applied. 10 | const modules = platformModules.concat(baseModules) 11 | 12 | export const patch: Function = createPatchFunction({ 13 | nodeOps, 14 | modules, 15 | LONG_LIST_THRESHOLD: 10 16 | }) 17 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/server/util.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export const isJS = (file: string): boolean => /\.js(\?[^.]+)?$/.test(file) 4 | 5 | export const isCSS = (file: string): boolean => /\.css(\?[^.]+)?$/.test(file) 6 | 7 | export function createPromiseCallback () { 8 | let resolve, reject 9 | const promise: Promise = new Promise((_resolve, _reject) => { 10 | resolve = _resolve 11 | reject = _reject 12 | }) 13 | const cb = (err: Error, res?: string) => { 14 | if (err) return reject(err) 15 | resolve(res || '') 16 | } 17 | return { promise, cb } 18 | } 19 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 确保脚本抛出遇到的错误 4 | set -e 5 | 6 | # 生成静态文件 7 | npm run build 8 | 9 | # 进入生成的文件夹 10 | cd docs/.vuepress/dist 11 | 12 | # 如果是发布到自定义域名 13 | # echo 'www.example.com' > CNAME 14 | 15 | git init 16 | git add -A 17 | git commit -m 'deploy' 18 | 19 | # 如果发布到 https://.github.io 20 | # git push -f git@github.com:/.github.io.git master 21 | 22 | # 如果发布到 https://.github.io/ 23 | # 发布到 lefex.github.io/fe-mini-course 下 24 | # git push -f git@github.com:lefex/fe-mini-course.git master:gh-pages 25 | # 发布到 lefex.github.io 下 26 | git push -f git@github.com:lefex/bat.git master:gh-pages 27 | 28 | cd - -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/util/perf.js: -------------------------------------------------------------------------------- 1 | import { inBrowser } from './env' 2 | 3 | export let mark 4 | export let measure 5 | 6 | if (process.env.NODE_ENV !== 'production') { 7 | const perf = inBrowser && window.performance 8 | /* istanbul ignore if */ 9 | if ( 10 | perf && 11 | perf.mark && 12 | perf.measure && 13 | perf.clearMarks && 14 | perf.clearMeasures 15 | ) { 16 | mark = tag => perf.mark(tag) 17 | measure = (name, startTag, endTag) => { 18 | perf.measure(name, startTag, endTag) 19 | perf.clearMarks(startTag) 20 | perf.clearMarks(endTag) 21 | // perf.clearMeasures(name) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/modules/recycle-list/component.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addAttr } from 'compiler/helpers' 4 | import { RECYCLE_LIST_MARKER } from 'weex/util/index' 5 | 6 | // mark components as inside recycle-list so that we know we need to invoke 7 | // their special @render function instead of render in create-component.js 8 | export function postTransformComponent ( 9 | el: ASTElement, 10 | options: WeexCompilerOptions 11 | ) { 12 | // $flow-disable-line (we know isReservedTag is there) 13 | if (!options.isReservedTag(el.tag) && el.tag !== 'cell-slot') { 14 | addAttr(el, RECYCLE_LIST_MARKER, 'true') 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/compiler/options.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { 4 | isPreTag, 5 | mustUseProp, 6 | isReservedTag, 7 | getTagNamespace 8 | } from '../util/index' 9 | 10 | import modules from './modules/index' 11 | import directives from './directives/index' 12 | import { genStaticKeys } from 'shared/util' 13 | import { isUnaryTag, canBeLeftOpenTag } from './util' 14 | 15 | export const baseOptions: CompilerOptions = { 16 | expectHTML: true, 17 | modules, 18 | directives, 19 | isPreTag, 20 | isUnaryTag, 21 | mustUseProp, 22 | canBeLeftOpenTag, 23 | isReservedTag, 24 | getTagNamespace, 25 | staticKeys: genStaticKeys(modules) 26 | } 27 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/server/optimizing-compiler/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { parse } from 'compiler/parser/index' 4 | import { generate } from './codegen' 5 | import { optimize } from './optimizer' 6 | import { createCompilerCreator } from 'compiler/create-compiler' 7 | 8 | export const createCompiler = createCompilerCreator(function baseCompile ( 9 | template: string, 10 | options: CompilerOptions 11 | ): CompiledResult { 12 | const ast = parse(template.trim(), options) 13 | optimize(ast, options) 14 | const code = generate(ast, options) 15 | return { 16 | ast, 17 | render: code.render, 18 | staticRenderFns: code.staticRenderFns 19 | } 20 | }) 21 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/instance/index.js: -------------------------------------------------------------------------------- 1 | import { initMixin } from './init' 2 | import { stateMixin } from './state' 3 | import { renderMixin } from './render' 4 | import { eventsMixin } from './events' 5 | import { lifecycleMixin } from './lifecycle' 6 | import { warn } from '../util/index' 7 | 8 | function Vue (options) { 9 | if (process.env.NODE_ENV !== 'production' && 10 | !(this instanceof Vue) 11 | ) { 12 | warn('Vue is a constructor and should be called with the `new` keyword') 13 | } 14 | this._init(options) 15 | } 16 | 17 | initMixin(Vue) 18 | stateMixin(Vue) 19 | eventsMixin(Vue) 20 | lifecycleMixin(Vue) 21 | renderMixin(Vue) 22 | 23 | export default Vue 24 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/layouts/404.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 31 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/arrow.styl: -------------------------------------------------------------------------------- 1 | @require './config' 2 | 3 | .arrow 4 | display inline-block 5 | width 0 6 | height 0 7 | &.up 8 | border-left 4px solid transparent 9 | border-right 4px solid transparent 10 | border-bottom 6px solid $arrowBgColor 11 | &.down 12 | border-left 4px solid transparent 13 | border-right 4px solid transparent 14 | border-top 6px solid $arrowBgColor 15 | &.right 16 | border-top 4px solid transparent 17 | border-bottom 4px solid transparent 18 | border-left 6px solid $arrowBgColor 19 | &.left 20 | border-top 4px solid transparent 21 | border-bottom 4px solid transparent 22 | border-right 6px solid $arrowBgColor 23 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/util/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { warn } from 'core/util/index' 4 | 5 | export * from './attrs' 6 | export * from './class' 7 | export * from './element' 8 | 9 | /** 10 | * Query an element selector if it's not an element already. 11 | */ 12 | export function query (el: string | Element): Element { 13 | if (typeof el === 'string') { 14 | const selected = document.querySelector(el) 15 | if (!selected) { 16 | process.env.NODE_ENV !== 'production' && warn( 17 | 'Cannot find element: ' + el 18 | ) 19 | return document.createElement('div') 20 | } 21 | return selected 22 | } else { 23 | return el 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/modules/recycle-list/text.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addAttr } from 'compiler/helpers' 4 | 5 | function genText (node: ASTNode) { 6 | const value = node.type === 3 7 | ? node.text 8 | : node.type === 2 9 | ? node.tokens.length === 1 10 | ? node.tokens[0] 11 | : node.tokens 12 | : '' 13 | return JSON.stringify(value) 14 | } 15 | 16 | export function postTransformText (el: ASTElement) { 17 | // weex can only contain text, so the parser 18 | // always generates a single child. 19 | if (el.children.length) { 20 | addAttr(el, 'value', genText(el.children[0])) 21 | el.children = [] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/Page.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 23 | 24 | 32 | -------------------------------------------------------------------------------- /docs/css/index.md: -------------------------------------------------------------------------------- 1 | # css 2 | 3 | - 介绍下 BFC、IFC、GFC 和 FFC 4 | - 如何解决移动端 Retina 屏 1px 像素问题 5 | - 已知如下代码,如何修改才能让图片宽度为 300px ?注意下面代码不可修改。 6 | ```html 7 | ` : `
` 10 | return div.innerHTML.indexOf(' ') > 0 11 | } 12 | 13 | // #3663: IE encodes newlines inside attribute values while other browsers don't 14 | export const shouldDecodeNewlines = inBrowser ? getShouldDecode(false) : false 15 | // #6828: chrome encodes content in a[href] 16 | export const shouldDecodeNewlinesForHref = inBrowser ? getShouldDecode(true) : false 17 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/DropdownTransition.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 28 | 29 | 34 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/instance/render-helpers/bind-object-listeners.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { warn, extend, isPlainObject } from 'core/util/index' 4 | 5 | export function bindObjectListeners (data: any, value: any): VNodeData { 6 | if (value) { 7 | if (!isPlainObject(value)) { 8 | process.env.NODE_ENV !== 'production' && warn( 9 | 'v-on without argument expects an Object value', 10 | this 11 | ) 12 | } else { 13 | const on = data.on = data.on ? extend({}, data.on) : {} 14 | for (const key in value) { 15 | const existing = on[key] 16 | const ours = value[key] 17 | on[key] = existing ? [].concat(existing, ours) : ours 18 | } 19 | } 20 | } 21 | return data 22 | } 23 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/global-api/use.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { toArray } from '../util/index' 4 | 5 | export function initUse (Vue: GlobalAPI) { 6 | Vue.use = function (plugin: Function | Object) { 7 | const installedPlugins = (this._installedPlugins || (this._installedPlugins = [])) 8 | if (installedPlugins.indexOf(plugin) > -1) { 9 | return this 10 | } 11 | 12 | // additional parameters 13 | const args = toArray(arguments, 1) 14 | args.unshift(this) 15 | if (typeof plugin.install === 'function') { 16 | plugin.install.apply(plugin, args) 17 | } else if (typeof plugin === 'function') { 18 | plugin.apply(null, args) 19 | } 20 | installedPlugins.push(plugin) 21 | return this 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/modules/recycle-list/v-bind.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { camelize } from 'shared/util' 4 | import { generateBinding } from 'weex/util/parser' 5 | import { bindRE } from 'compiler/parser/index' 6 | import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers' 7 | 8 | function parseAttrName (name: string): string { 9 | return camelize(name.replace(bindRE, '')) 10 | } 11 | 12 | export function preTransformVBind (el: ASTElement) { 13 | for (const attr in el.attrsMap) { 14 | if (bindRE.test(attr)) { 15 | const name: string = parseAttrName(attr) 16 | const value = generateBinding(getAndRemoveAttr(el, attr)) 17 | delete el.attrsMap[attr] 18 | addRawAttr(el, name, value) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /docs/network/index.md: -------------------------------------------------------------------------------- 1 | # 前端网络相关的面试题 2 | 3 | 网格相关内容主要围绕下面这些面试题进行展开,每道面试题都是从一个点展开,由浅入深,在做面试题的同时掌握知识。 4 | 5 | - [第 1 题:前端网络请求都有哪些方式?webSocket 是什么?](https://lefex.github.io/bat/network/1) 6 | - [第 2 题:工作中是否遇到过跨域?什么是跨域?如何解决?](https://lefex.github.io/bat/network/2) 7 | - [第 3 题:为什么通常在发送数据埋点请求的时候使用的是 1x1 像素的透明 gif 图片?](https://lefex.github.io/bat/network/3) 8 | - [第 4 题:谈谈你对TCP的理解](https://lefex.github.io/bat/network/4) 9 | - [第 5 题:从输入一个url到呈现网页,都有哪些步骤](https://lefex.github.io/bat/network/5) 10 | - [第 6 题:谈谈你对 HTTP 的理解,状态码的含义,header 定义](https://lefex.github.io/bat/network/6) 11 | - [第 7 题:谈谈你对 https 的理解](https://lefex.github.io/bat/network/7) 12 | - [第 8 题:谈谈你对 HTTP2 的理解](https://lefex.github.io/bat/network/8) 13 | - [第 9 题:axios 是如何实现的](https://lefex.github.io/bat/network/9) 14 | 15 | 16 | -------------------------------------------------------------------------------- /main/src/App.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 16 | 17 | 31 | -------------------------------------------------------------------------------- /docs/js/7.md: -------------------------------------------------------------------------------- 1 | # 如何理解 JavaScript 异步执行机制 2 | 3 | 下面这段代码的执行顺序是什么? 4 | 5 | ```js 6 | async function async1() { 7 | console.log('async1 start'); 8 | await async2(); 9 | console.log('async1 end'); 10 | } 11 | 12 | function async2() { 13 | console.log('async2 start'); 14 | } 15 | 16 | console.log('start'); 17 | 18 | setTimeout(function() { 19 | console.log('setTimeout excuted'); 20 | }, 0) 21 | async1(); 22 | 23 | new Promise(function(resolve) { 24 | console.log('promise resolve'); 25 | resolve(); 26 | }).then(function() { 27 | console.log('promise then'); 28 | }); 29 | 30 | console.log('end'); 31 | ``` 32 | 33 | 代码执行结果: 34 | 35 | ```js 36 | start 37 | async1 start 38 | async2 start 39 | promise resolve 40 | end 41 | async1 end 42 | promise then 43 | setTimeout excuted 44 | ``` -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { Vue } from "./vue"; 2 | import "./umd"; 3 | 4 | export default Vue; 5 | 6 | export { 7 | CreateElement, 8 | VueConstructor 9 | } from "./vue"; 10 | 11 | export { 12 | Component, 13 | AsyncComponent, 14 | ComponentOptions, 15 | FunctionalComponentOptions, 16 | RenderContext, 17 | PropType, 18 | PropOptions, 19 | ComputedOptions, 20 | WatchHandler, 21 | WatchOptions, 22 | WatchOptionsWithHandler, 23 | DirectiveFunction, 24 | DirectiveOptions 25 | } from "./options"; 26 | 27 | export { 28 | PluginFunction, 29 | PluginObject 30 | } from "./plugin"; 31 | 32 | export { 33 | VNodeChildren, 34 | VNodeChildrenArrayContents, 35 | VNode, 36 | VNodeComponentOptions, 37 | VNodeData, 38 | VNodeDirective 39 | } from "./vnode"; 40 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/index.js: -------------------------------------------------------------------------------- 1 | import Vue from './instance/index' 2 | import { initGlobalAPI } from './global-api/index' 3 | import { isServerRendering } from 'core/util/env' 4 | import { FunctionalRenderContext } from 'core/vdom/create-functional-component' 5 | 6 | initGlobalAPI(Vue) 7 | 8 | Object.defineProperty(Vue.prototype, '$isServer', { 9 | get: isServerRendering 10 | }) 11 | 12 | Object.defineProperty(Vue.prototype, '$ssrContext', { 13 | get () { 14 | /* istanbul ignore next */ 15 | return this.$vnode && this.$vnode.ssrContext 16 | } 17 | }) 18 | 19 | // expose FunctionalRenderContext for ssr runtime helper installation 20 | Object.defineProperty(Vue, 'FunctionalRenderContext', { 21 | value: FunctionalRenderContext 22 | }) 23 | 24 | Vue.version = '__VERSION__' 25 | 26 | export default Vue 27 | -------------------------------------------------------------------------------- /main/src/topic/iterator.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 迭代器 3 | */ 4 | 5 | export function runIterator() { 6 | class MyIterator implements Iterator { 7 | private currentIndex: number = 0; 8 | private items: T[]; 9 | 10 | constructor(items: T[]) { 11 | this.items = items; 12 | } 13 | 14 | public next(): IteratorResult { 15 | if (this.currentIndex < this.items.length) { 16 | let ret = { 17 | value: this.items[this.currentIndex] 18 | } 19 | this.currentIndex += 1; 20 | return ret; 21 | } 22 | return { 23 | done: true, 24 | value: null 25 | } 26 | } 27 | } 28 | 29 | const myIterable = [1, 2, 3, 4, 5]; 30 | const myIterator = new MyIterator(myIterable); 31 | 32 | for (const item of myIterator) { 33 | console.log(item); 34 | } 35 | } -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/modules/append.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { makeMap } from 'shared/util' 4 | 5 | // The "unitary tag" means that the tag node and its children 6 | // must be sent to the native together. 7 | const isUnitaryTag = makeMap('cell,header,cell-slot,recycle-list', true) 8 | 9 | function preTransformNode (el: ASTElement) { 10 | if (isUnitaryTag(el.tag) && !el.attrsList.some(item => item.name === 'append')) { 11 | el.attrsMap.append = 'tree' 12 | el.attrsList.push({ name: 'append', value: 'tree' }) 13 | } 14 | if (el.attrsMap.append === 'tree') { 15 | el.appendAsTree = true 16 | } 17 | } 18 | 19 | function genData (el: ASTElement): string { 20 | return el.appendAsTree ? `appendAsTree:true,` : '' 21 | } 22 | 23 | export default { 24 | staticKeys: ['appendAsTree'], 25 | preTransformNode, 26 | genData 27 | } 28 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/modules/recycle-list/v-on.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | const inlineStatementRE = /^\s*([A-Za-z_$0-9\['\."\]]+)*\s*\(\s*(([A-Za-z_$0-9\['\."\]]+)?(\s*,\s*([A-Za-z_$0-9\['\."\]]+))*)\s*\)$/ 4 | 5 | function parseHandlerParams (handler: ASTElementHandler) { 6 | const res = inlineStatementRE.exec(handler.value) 7 | if (res && res[2]) { 8 | handler.params = res[2].split(/\s*,\s*/) 9 | } 10 | } 11 | 12 | export function postTransformVOn (el: ASTElement) { 13 | const events: ASTElementHandlers | void = el.events 14 | if (!events) { 15 | return 16 | } 17 | for (const name in events) { 18 | const handler: ASTElementHandler | Array = events[name] 19 | if (Array.isArray(handler)) { 20 | handler.map(fn => parseHandlerParams(fn)) 21 | } else { 22 | parseHandlerParams(handler) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/instance/render-helpers/resolve-scoped-slots.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export function resolveScopedSlots ( 4 | fns: ScopedSlotsData, // see flow/vnode 5 | res?: Object, 6 | // the following are added in 2.6 7 | hasDynamicKeys?: boolean, 8 | contentHashKey?: number 9 | ): { [key: string]: Function, $stable: boolean } { 10 | res = res || { $stable: !hasDynamicKeys } 11 | for (let i = 0; i < fns.length; i++) { 12 | const slot = fns[i] 13 | if (Array.isArray(slot)) { 14 | resolveScopedSlots(slot, res, hasDynamicKeys) 15 | } else if (slot) { 16 | // marker for reverse proxying v-slot without scope on this.$slots 17 | if (slot.proxy) { 18 | slot.fn.proxy = true 19 | } 20 | res[slot.key] = slot.fn 21 | } 22 | } 23 | if (contentHashKey) { 24 | (res: any).$key = contentHashKey 25 | } 26 | return res 27 | } 28 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/compiler/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { parse } from './parser/index' 4 | import { optimize } from './optimizer' 5 | import { generate } from './codegen/index' 6 | import { createCompilerCreator } from './create-compiler' 7 | 8 | // `createCompilerCreator` allows creating compilers that use alternative 9 | // parser/optimizer/codegen, e.g the SSR optimizing compiler. 10 | // Here we just export a default compiler using the default parts. 11 | export const createCompiler = createCompilerCreator(function baseCompile ( 12 | template: string, 13 | options: CompilerOptions 14 | ): CompiledResult { 15 | const ast = parse(template.trim(), options) 16 | if (options.optimize !== false) { 17 | optimize(ast, options) 18 | } 19 | const code = generate(ast, options) 20 | return { 21 | ast, 22 | render: code.render, 23 | staticRenderFns: code.staticRenderFns 24 | } 25 | }) 26 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/mobile.styl: -------------------------------------------------------------------------------- 1 | @require './config' 2 | 3 | $mobileSidebarWidth = $sidebarWidth * 0.82 4 | 5 | // narrow desktop / iPad 6 | @media (max-width: $MQNarrow) 7 | .sidebar 8 | font-size 15px 9 | width $mobileSidebarWidth 10 | .page 11 | padding-left $mobileSidebarWidth 12 | 13 | // wide mobile 14 | @media (max-width: $MQMobile) 15 | .sidebar 16 | top 0 17 | padding-top $navbarHeight 18 | transform translateX(-100%) 19 | transition transform .2s ease 20 | .page 21 | padding-left 0 22 | .theme-container 23 | &.sidebar-open 24 | .sidebar 25 | transform translateX(0) 26 | &.no-navbar 27 | .sidebar 28 | padding-top: 0 29 | 30 | // narrow mobile 31 | @media (max-width: $MQMobileNarrow) 32 | h1 33 | font-size 1.9rem 34 | {$contentClass} 35 | div[class*="language-"] 36 | margin 0.85rem -1.5rem 37 | border-radius 0 38 | -------------------------------------------------------------------------------- /src/js/this.js: -------------------------------------------------------------------------------- 1 | function demo1() { 2 | function foo(num) { 3 | // foo.count++; 4 | console.log('foo:' + num); 5 | // console.log(this.count); NAN 6 | this.count++; 7 | } 8 | foo.count = 0; 9 | 10 | var i; 11 | for(i = 0; i < 10; i++) { 12 | if (i > 5) { 13 | foo(i); 14 | // foo.call(foo, i); this 为 foo 15 | } 16 | } 17 | console.log(foo.count); 18 | } 19 | 20 | function demo2() { 21 | var a = 2; 22 | function foo(num) { 23 | // 严格模式 undefined 24 | // 非严格模式 2 25 | console.log(this.a); 26 | } 27 | // 函数的默认绑定 28 | // foo(); 29 | } 30 | 31 | function demo3() { 32 | function foo(num) { 33 | // 2 34 | console.log(this.a); 35 | } 36 | var obj = { 37 | a: 2, 38 | foo: foo 39 | }; 40 | obj.foo(); // 2 41 | // 隐式绑定 42 | } 43 | 44 | 45 | 46 | demo3(); -------------------------------------------------------------------------------- /docs/js/3.md: -------------------------------------------------------------------------------- 1 | # 第 3 题:谈谈浏览器的事件循环 2 | 3 | 事件循环不是 JavaScript 引擎实现的,JavaScript 引擎只负责把一段 JavaScript 代码执行。事件循环是它所在的宿主环境实现的,类似下面的代码: 4 | 5 | ```js 6 | function eventLoop() { 7 | var eventLoop = []; 8 | var event; 9 | while(true) { 10 | if (eventLoop.length > 0) { 11 | event = eventLoop.shift(); 12 | 13 | try { 14 | event(); 15 | } catch (e) { 16 | 17 | } 18 | } 19 | } 20 | } 21 | ``` 22 | 23 | 一定要清楚,setTimeout(..) 并没有把你的回调函数挂在事件循环队列中。它所做的是设定一个定时器。当定时器到时后,环境会把你的回调函数放在事件循环中,这样,在未来某个时刻的tick 会摘下并执行这个回调。 24 | 25 | 如果这时候事件循环中已经有 20 个项目了会怎样呢?你的回调就会等待。它得排在 其他项目后面——通常没有抢占式的方式支持直接将其排到队首。这也解释了为什么 setTimeout(..) 定时器的精度可能不高。大体说来,只能确保你的回调函数不会在指定的 时间间隔之前运行,但可能会在那个时刻运行,也可能在那之后运行,要根据事件队列的 状态而定。 26 | 27 | JavaScript 是运行在单线程下的,也就是如果一个函数开始执行,它是原子性的,不会被其它要执行的代码所打断,是完整运行的。 28 | 29 | 30 | ### 相关面试题 31 | 32 | - 对settimeout和对setinterval的理解(涉及代码题倒计时函数,eventloop的考点)计时是否准确?如何实现较为准确的计时? -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/modules/recycle-list/v-for.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { parseFor } from 'compiler/parser/index' 4 | import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers' 5 | 6 | export function preTransformVFor (el: ASTElement, options: WeexCompilerOptions) { 7 | const exp = getAndRemoveAttr(el, 'v-for') 8 | if (!exp) { 9 | return 10 | } 11 | 12 | const res = parseFor(exp) 13 | if (!res) { 14 | if (process.env.NODE_ENV !== 'production' && options.warn) { 15 | options.warn(`Invalid v-for expression: ${exp}`) 16 | } 17 | return 18 | } 19 | 20 | const desc: Object = { 21 | '@expression': res.for, 22 | '@alias': res.alias 23 | } 24 | if (res.iterator2) { 25 | desc['@key'] = res.iterator1 26 | desc['@index'] = res.iterator2 27 | } else { 28 | desc['@index'] = res.iterator1 29 | } 30 | 31 | delete el.attrsMap['v-for'] 32 | addRawAttr(el, '[[repeat]]', desc) 33 | } 34 | -------------------------------------------------------------------------------- /main/src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 33 | 34 | 39 | -------------------------------------------------------------------------------- /src/js/eventloop.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 |
8 | 9 | 10 | 35 | 36 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/server/create-basic-renderer.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { createWriteFunction } from './write' 4 | import { createRenderFunction } from './render' 5 | import type { RenderOptions } from './create-renderer' 6 | 7 | export function createBasicRenderer ({ 8 | modules = [], 9 | directives = {}, 10 | isUnaryTag = (() => false), 11 | cache 12 | }: RenderOptions = {}) { 13 | const render = createRenderFunction(modules, directives, isUnaryTag, cache) 14 | 15 | return function renderToString ( 16 | component: Component, 17 | context: any, 18 | done: any 19 | ): void { 20 | if (typeof context === 'function') { 21 | done = context 22 | context = {} 23 | } 24 | let result = '' 25 | const write = createWriteFunction(text => { 26 | result += text 27 | return false 28 | }, done) 29 | try { 30 | render(component, write, context, () => { 31 | done(null, result) 32 | }) 33 | } catch (e) { 34 | done(e) 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/global-components/Badge.vue: -------------------------------------------------------------------------------- 1 | 25 | 26 | 45 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/compiler/util.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { makeMap } from 'shared/util' 4 | 5 | export const isUnaryTag = makeMap( 6 | 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' + 7 | 'link,meta,param,source,track,wbr' 8 | ) 9 | 10 | // Elements that you can, intentionally, leave open 11 | // (and which close themselves) 12 | export const canBeLeftOpenTag = makeMap( 13 | 'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source' 14 | ) 15 | 16 | // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3 17 | // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content 18 | export const isNonPhrasingTag = makeMap( 19 | 'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' + 20 | 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' + 21 | 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' + 22 | 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' + 23 | 'title,tr,track' 24 | ) 25 | -------------------------------------------------------------------------------- /question.md: -------------------------------------------------------------------------------- 1 | # 面试题未整理 2 | 3 | 4 | - 模拟实现一个深拷贝,并考虑对象相互引用以及 Symbol 拷贝的情况 5 | - 请分别用深度优先思想和广度优先思想实现一个拷贝函数? 6 | - 介绍下深度优先遍历和广度优先遍历,如何实现? 7 | 8 | - 实现 convert 方法,把原始 list 转换成树形结构,要求尽可能降低时间复杂度 9 | 10 | 11 | - 使用 JavaScript Proxy 实现简单的数据绑定 12 | - 实现一个字符串匹配算法,从长度为 n 的字符串 S 中,查找是否存在字符串 T,T 的长度是 m,若存在返回所在位置。 13 | - a.b.c.d 和 a['b']['c']['d'],哪个性能更高? 14 | - 箭头函数与普通函数(function)的区别是什么?构造函数(function)可以使用 new 生成实例,那么箭头函数可以吗?为什么? 15 | 16 | - 某公司 1 到 12 月份的销售额存在一个对象里面 17 | 如下:{1:222, 2:123, 5:888},请把数据处理为如下结构:[222, 123, null, null, 888, null, null, null, null, null, null, null]。 18 | 19 | 20 | 21 | - 使用迭代的方式实现 flatten 函数。 22 | 23 | 24 | - 介绍模块化发展历程 25 | - 有以下 3 个判断数组的方法,请分别介绍它们之间的区别和优劣 26 | Object.prototype.toString.call() 、 instanceof 以及 Array.isArray() 27 | - 情人节福利题,如何实现一个 new 28 | 29 | 30 | 31 | - 什么是防抖和节流?有什么区别?如何实现? 32 | - ['1', '2', '3'].map(parseInt) what & why ? 33 | 34 | - 写一个倒计时函数 35 | 36 | - 什么情况会造成内存泄露(setTimeout, setInterval),还有呢? 37 | - 给数组添加元素的方法 38 | 39 | 40 | 41 | 42 | 43 | ### 参考 44 | 45 | - [Promise](https://zhuanlan.zhihu.com/p/30797777) -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/entry-server-renderer.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | process.env.VUE_ENV = 'server' 4 | 5 | import { extend } from 'shared/util' 6 | import modules from './server/modules/index' 7 | import baseDirectives from './server/directives/index' 8 | import { isUnaryTag, canBeLeftOpenTag } from './compiler/util' 9 | 10 | import { createRenderer as _createRenderer } from 'server/create-renderer' 11 | import { createBundleRendererCreator } from 'server/bundle-renderer/create-bundle-renderer' 12 | 13 | export function createRenderer (options?: Object = {}): { 14 | renderToString: Function, 15 | renderToStream: Function 16 | } { 17 | return _createRenderer(extend(extend({}, options), { 18 | isUnaryTag, 19 | canBeLeftOpenTag, 20 | modules, 21 | // user can provide server-side implementations for custom directives 22 | // when creating the renderer. 23 | directives: extend(baseDirectives, options.directives) 24 | })) 25 | } 26 | 27 | export const createBundleRenderer = createBundleRendererCreator(createRenderer) 28 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/directives/model.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addHandler, addAttr } from 'compiler/helpers' 4 | import { genComponentModel, genAssignmentCode } from 'compiler/directives/model' 5 | 6 | export default function model ( 7 | el: ASTElement, 8 | dir: ASTDirective 9 | ): ?boolean { 10 | if (el.tag === 'input' || el.tag === 'textarea') { 11 | genDefaultModel(el, dir.value, dir.modifiers) 12 | } else { 13 | genComponentModel(el, dir.value, dir.modifiers) 14 | } 15 | } 16 | 17 | function genDefaultModel ( 18 | el: ASTElement, 19 | value: string, 20 | modifiers: ?ASTModifiers 21 | ): ?boolean { 22 | const { lazy, trim, number } = modifiers || {} 23 | const event = lazy ? 'change' : 'input' 24 | 25 | let valueExpression = `$event.target.attr.value${trim ? '.trim()' : ''}` 26 | if (number) { 27 | valueExpression = `_n(${valueExpression})` 28 | } 29 | 30 | const code = genAssignmentCode(value, valueExpression) 31 | addAttr(el, 'value', `(${value})`) 32 | addHandler(el, event, code, null, true) 33 | } 34 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/instance/render-helpers/render-slot.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { extend, warn, isObject } from 'core/util/index' 4 | 5 | /** 6 | * Runtime helper for rendering 7 | */ 8 | export function renderSlot ( 9 | name: string, 10 | fallback: ?Array, 11 | props: ?Object, 12 | bindObject: ?Object 13 | ): ?Array { 14 | const scopedSlotFn = this.$scopedSlots[name] 15 | let nodes 16 | if (scopedSlotFn) { // scoped slot 17 | props = props || {} 18 | if (bindObject) { 19 | if (process.env.NODE_ENV !== 'production' && !isObject(bindObject)) { 20 | warn( 21 | 'slot v-bind without argument expects an Object', 22 | this 23 | ) 24 | } 25 | props = extend(extend({}, bindObject), props) 26 | } 27 | nodes = scopedSlotFn(props) || fallback 28 | } else { 29 | nodes = this.$slots[name] || fallback 30 | } 31 | 32 | const target = props && props.slot 33 | if (target) { 34 | return this.$createElement('template', { slot: target }, nodes) 35 | } else { 36 | return nodes 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 suyan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/observer/traverse.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { _Set as Set, isObject } from '../util/index' 4 | import type { SimpleSet } from '../util/index' 5 | import VNode from '../vdom/vnode' 6 | 7 | const seenObjects = new Set() 8 | 9 | /** 10 | * Recursively traverse an object to evoke all converted 11 | * getters, so that every nested property inside the object 12 | * is collected as a "deep" dependency. 13 | */ 14 | export function traverse (val: any) { 15 | _traverse(val, seenObjects) 16 | seenObjects.clear() 17 | } 18 | 19 | function _traverse (val: any, seen: SimpleSet) { 20 | let i, keys 21 | const isA = Array.isArray(val) 22 | if ((!isA && !isObject(val)) || Object.isFrozen(val) || val instanceof VNode) { 23 | return 24 | } 25 | if (val.__ob__) { 26 | const depId = val.__ob__.dep.id 27 | if (seen.has(depId)) { 28 | return 29 | } 30 | seen.add(depId) 31 | } 32 | if (isA) { 33 | i = val.length 34 | while (i--) _traverse(val[i], seen) 35 | } else { 36 | keys = Object.keys(val) 37 | i = keys.length 38 | while (i--) _traverse(val[keys[i]], seen) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/runtime/modules/class.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { 4 | isDef, 5 | isUndef 6 | } from 'shared/util' 7 | 8 | import { 9 | concat, 10 | stringifyClass, 11 | genClassForVnode 12 | } from 'web/util/index' 13 | 14 | function updateClass (oldVnode: any, vnode: any) { 15 | const el = vnode.elm 16 | const data: VNodeData = vnode.data 17 | const oldData: VNodeData = oldVnode.data 18 | if ( 19 | isUndef(data.staticClass) && 20 | isUndef(data.class) && ( 21 | isUndef(oldData) || ( 22 | isUndef(oldData.staticClass) && 23 | isUndef(oldData.class) 24 | ) 25 | ) 26 | ) { 27 | return 28 | } 29 | 30 | let cls = genClassForVnode(vnode) 31 | 32 | // handle transition classes 33 | const transitionClass = el._transitionClasses 34 | if (isDef(transitionClass)) { 35 | cls = concat(cls, stringifyClass(transitionClass)) 36 | } 37 | 38 | // set the class 39 | if (cls !== el._prevClass) { 40 | el.setAttribute('class', cls) 41 | el._prevClass = cls 42 | } 43 | } 44 | 45 | export default { 46 | create: updateClass, 47 | update: updateClass 48 | } 49 | -------------------------------------------------------------------------------- /main/src/topic/microtasks.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * a microtask is a small unit of code that is queued for execution on the microtask queue 3 | * 微任务是一个运行在微任务队列中的任务,其实就是一段代码 4 | * Microtasks are typically used for tasks that need to be executed as soon as possible, 5 | * such as updating the UI after a state change or performing some other small, time-sensitive 6 | * operation. 7 | * 微任务通常是需要紧急执行,不耗时的事件,比如刷新UI 8 | * 本质上其实就是控制代码执行流程,能够异步执行代码,而不卡主线程 9 | */ 10 | export const runMicrotasks = function() { 11 | // 在当前任务中执行 12 | console.log('microtasks run'); 13 | console.log('start'); 14 | 15 | // 放到微任务队列中执行 16 | Promise.resolve().then(() => { 17 | console.log('microtask 1'); 18 | }); 19 | 20 | // 放到微任务队列中执行 21 | Promise.resolve().then(() => { 22 | console.log('microtask 2'); 23 | }); 24 | 25 | // 在当前任务中执行 26 | console.log('end'); 27 | 28 | let count = 0; 29 | function increment() { 30 | count++; 31 | // 在微任务中更新UI 32 | queueMicrotask(() => { 33 | document.getElementById('count')!.textContent = `${count}`; 34 | }); 35 | } 36 | document.getElementById('button')!.addEventListener('click', increment); 37 | 38 | 39 | 40 | } -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/server/webpack-plugin/util.js: -------------------------------------------------------------------------------- 1 | const { red, yellow } = require('chalk') 2 | 3 | const prefix = `[vue-server-renderer-webpack-plugin]` 4 | const warn = exports.warn = msg => console.error(red(`${prefix} ${msg}\n`)) 5 | const tip = exports.tip = msg => console.log(yellow(`${prefix} ${msg}\n`)) 6 | 7 | export const validate = compiler => { 8 | if (compiler.options.target !== 'node') { 9 | warn('webpack config `target` should be "node".') 10 | } 11 | 12 | if (compiler.options.output && compiler.options.output.libraryTarget !== 'commonjs2') { 13 | warn('webpack config `output.libraryTarget` should be "commonjs2".') 14 | } 15 | 16 | if (!compiler.options.externals) { 17 | tip( 18 | 'It is recommended to externalize dependencies in the server build for ' + 19 | 'better build performance.' 20 | ) 21 | } 22 | } 23 | 24 | export const onEmit = (compiler, name, hook) => { 25 | if (compiler.hooks) { 26 | // Webpack >= 4.0.0 27 | compiler.hooks.emit.tapAsync(name, hook) 28 | } else { 29 | // Webpack < 4.0.0 30 | compiler.plugin('emit', hook) 31 | } 32 | } 33 | 34 | export { isJS, isCSS } from '../util' 35 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-present, Yuxi (Evan) You 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/modules/props.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { cached, camelize } from 'shared/util' 4 | 5 | const normalize = cached(camelize) 6 | 7 | function normalizeKeyName (str: string): string { 8 | if (str.match(/^v\-/)) { 9 | return str.replace(/(v-[a-z\-]+\:)([a-z\-]+)$/i, ($, directive, prop) => { 10 | return directive + normalize(prop) 11 | }) 12 | } 13 | return normalize(str) 14 | } 15 | 16 | function transformNode (el: ASTElement) { 17 | if (Array.isArray(el.attrsList)) { 18 | el.attrsList.forEach(attr => { 19 | if (attr.name && attr.name.match(/\-/)) { 20 | const realName = normalizeKeyName(attr.name) 21 | if (el.attrsMap) { 22 | el.attrsMap[realName] = el.attrsMap[attr.name] 23 | delete el.attrsMap[attr.name] 24 | } 25 | if (el.rawAttrsMap && el.rawAttrsMap[attr.name]) { 26 | el.rawAttrsMap[realName] = el.rawAttrsMap[attr.name] 27 | // $flow-disable-line 28 | delete el.rawAttrsMap[attr.name] 29 | } 30 | attr.name = realName 31 | } 32 | }) 33 | } 34 | } 35 | export default { 36 | transformNode 37 | } 38 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018-present, Yuxi (Evan) You 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/custom-blocks.styl: -------------------------------------------------------------------------------- 1 | .custom-block 2 | .custom-block-title 3 | font-weight 600 4 | margin-bottom -0.4rem 5 | &.tip, &.warning, &.danger 6 | padding .1rem 1.5rem 7 | border-left-width .5rem 8 | border-left-style solid 9 | margin 1rem 0 10 | &.tip 11 | background-color #f3f5f7 12 | border-color #42b983 13 | &.warning 14 | background-color rgba(255,229,100,.3) 15 | border-color darken(#ffe564, 35%) 16 | color darken(#ffe564, 70%) 17 | .custom-block-title 18 | color darken(#ffe564, 50%) 19 | a 20 | color $textColor 21 | &.danger 22 | background-color #ffe6e6 23 | border-color darken(red, 20%) 24 | color darken(red, 70%) 25 | .custom-block-title 26 | color darken(red, 40%) 27 | a 28 | color $textColor 29 | &.details 30 | display block 31 | position relative 32 | border-radius 2px 33 | margin 1.6em 0 34 | padding 1.6em 35 | background-color #eee 36 | h4 37 | margin-top 0 38 | figure, p 39 | &:last-child 40 | margin-bottom 0 41 | padding-bottom 0 42 | summary 43 | outline none 44 | cursor pointer 45 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/instance/render-helpers/check-keycodes.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import config from 'core/config' 4 | import { hyphenate } from 'shared/util' 5 | 6 | function isKeyNotMatch (expect: T | Array, actual: T): boolean { 7 | if (Array.isArray(expect)) { 8 | return expect.indexOf(actual) === -1 9 | } else { 10 | return expect !== actual 11 | } 12 | } 13 | 14 | /** 15 | * Runtime helper for checking keyCodes from config. 16 | * exposed as Vue.prototype._k 17 | * passing in eventKeyName as last argument separately for backwards compat 18 | */ 19 | export function checkKeyCodes ( 20 | eventKeyCode: number, 21 | key: string, 22 | builtInKeyCode?: number | Array, 23 | eventKeyName?: string, 24 | builtInKeyName?: string | Array 25 | ): ?boolean { 26 | const mappedKeyCode = config.keyCodes[key] || builtInKeyCode 27 | if (builtInKeyName && eventKeyName && !config.keyCodes[key]) { 28 | return isKeyNotMatch(builtInKeyName, eventKeyName) 29 | } else if (mappedKeyCode) { 30 | return isKeyNotMatch(mappedKeyCode, eventKeyCode) 31 | } else if (eventKeyName) { 32 | return hyphenate(eventKeyName) !== key 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/observer/array.js: -------------------------------------------------------------------------------- 1 | /* 2 | * not type checking this file because flow doesn't play well with 3 | * dynamically accessing methods on Array prototype 4 | */ 5 | 6 | import { def } from '../util/index' 7 | 8 | const arrayProto = Array.prototype 9 | export const arrayMethods = Object.create(arrayProto) 10 | 11 | const methodsToPatch = [ 12 | 'push', 13 | 'pop', 14 | 'shift', 15 | 'unshift', 16 | 'splice', 17 | 'sort', 18 | 'reverse' 19 | ] 20 | 21 | /** 22 | * Intercept mutating methods and emit events 23 | */ 24 | methodsToPatch.forEach(function (method) { 25 | // cache original method 26 | const original = arrayProto[method] 27 | def(arrayMethods, method, function mutator (...args) { 28 | const result = original.apply(this, args) 29 | const ob = this.__ob__ 30 | let inserted 31 | switch (method) { 32 | case 'push': 33 | case 'unshift': 34 | inserted = args 35 | break 36 | case 'splice': 37 | inserted = args.slice(2) 38 | break 39 | } 40 | if (inserted) ob.observeArray(inserted) 41 | // notify change 42 | ob.dep.notify() 43 | return result 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/server/template-renderer/parse-template.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | const compile = require('lodash.template') 4 | const compileOptions = { 5 | escape: /{{([^{][\s\S]+?[^}])}}/g, 6 | interpolate: /{{{([\s\S]+?)}}}/g 7 | } 8 | 9 | export type ParsedTemplate = { 10 | head: (data: any) => string; 11 | neck: (data: any) => string; 12 | tail: (data: any) => string; 13 | }; 14 | 15 | export function parseTemplate ( 16 | template: string, 17 | contentPlaceholder?: string = '' 18 | ): ParsedTemplate { 19 | if (typeof template === 'object') { 20 | return template 21 | } 22 | 23 | let i = template.indexOf('') 24 | const j = template.indexOf(contentPlaceholder) 25 | 26 | if (j < 0) { 27 | throw new Error(`Content placeholder not found in template.`) 28 | } 29 | 30 | if (i < 0) { 31 | i = template.indexOf('') 32 | if (i < 0) { 33 | i = j 34 | } 35 | } 36 | 37 | return { 38 | head: compile(template.slice(0, i), compileOptions), 39 | neck: compile(template.slice(i, j), compileOptions), 40 | tail: compile(template.slice(j + contentPlaceholder.length), compileOptions) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /docs/js/1.md: -------------------------------------------------------------------------------- 1 | # 第 1 题:谈谈你对 Promise 的理解 2 | 3 | Promise 是一种异步编程机制,它非常可信任。 4 | 5 | ### 相关面试题 6 | 7 | - 设计并实现 Promise.race 8 | 9 | 意义:只要有一个 Promise 完成便完成,可以是 resolve 或 reject 10 | 11 | - 模拟实现一个 Promise.finally 12 | 13 | 意义:不管是 resolve 还是 reject 都会被调用 14 | 15 | - Promise 构造函数是同步执行还是异步执行,那么 then 方法呢? 16 | 17 | 构造函数是同步执行,then 方法是异步执行,通过 setTimeout 0 可以控制该任务在下一次事件循环中执行。 18 | 19 | - 介绍下 Promise.all 使用、原理实现及错误处理 20 | 意义:只有所有的任务 resolve 才会被 resolve,只要有一个 reject 就会 reject。Promise.all 本身会 new 一个新的 Promise 21 | 22 | - Promise是否了解,如何实现一个promise 23 | 这个比较难,需要准寻 Promise/A+ 规范来实现 24 | 25 | - async await 和 promise 的关系 26 | 27 | - JS 异步解决方案的发展历程以及优缺点。 28 | 29 | 1、callback 机制 30 | 2、Promise 31 | 3、生成器 generator 32 | 4、async、await 33 | 34 | promises-aplus-tests 可以测试 Promise 是否实现完美。 35 | 36 | ### 参考 37 | 38 | - [Promise MDN](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise) 39 | - [Promise/A+ 规范](https://promisesaplus.com/#notes) 40 | - [手写Promise](https://github.com/dream2023/blog/tree/master/2%E3%80%81promise%E5%8E%9F%E7%90%86) 41 | - [Promise/A+规范译文](https://www.ituring.com.cn/article/66566) 42 | - [你不知道的JS作者写的Promise](https://github.com/getify/native-promise-only) -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/SidebarButton.vue: -------------------------------------------------------------------------------- 1 | 21 | 22 | 41 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/vdom/helpers/merge-hook.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import VNode from '../vnode' 4 | import { createFnInvoker } from './update-listeners' 5 | import { remove, isDef, isUndef, isTrue } from 'shared/util' 6 | 7 | export function mergeVNodeHook (def: Object, hookKey: string, hook: Function) { 8 | if (def instanceof VNode) { 9 | def = def.data.hook || (def.data.hook = {}) 10 | } 11 | let invoker 12 | const oldHook = def[hookKey] 13 | 14 | function wrappedHook () { 15 | hook.apply(this, arguments) 16 | // important: remove merged hook to ensure it's called only once 17 | // and prevent memory leak 18 | remove(invoker.fns, wrappedHook) 19 | } 20 | 21 | if (isUndef(oldHook)) { 22 | // no existing hook 23 | invoker = createFnInvoker([wrappedHook]) 24 | } else { 25 | /* istanbul ignore if */ 26 | if (isDef(oldHook.fns) && isTrue(oldHook.merged)) { 27 | // already a merged invoker 28 | invoker = oldHook 29 | invoker.fns.push(wrappedHook) 30 | } else { 31 | // existing plain hook 32 | invoker = createFnInvoker([oldHook, wrappedHook]) 33 | } 34 | } 35 | 36 | invoker.merged = true 37 | def[hookKey] = invoker 38 | } 39 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/SubMainCard.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 28 | 29 | 53 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/global-api/assets.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { ASSET_TYPES } from 'shared/constants' 4 | import { isPlainObject, validateComponentName } from '../util/index' 5 | 6 | export function initAssetRegisters (Vue: GlobalAPI) { 7 | /** 8 | * Create asset registration methods. 9 | */ 10 | ASSET_TYPES.forEach(type => { 11 | Vue[type] = function ( 12 | id: string, 13 | definition: Function | Object 14 | ): Function | Object | void { 15 | if (!definition) { 16 | return this.options[type + 's'][id] 17 | } else { 18 | /* istanbul ignore if */ 19 | if (process.env.NODE_ENV !== 'production' && type === 'component') { 20 | validateComponentName(id) 21 | } 22 | if (type === 'component' && isPlainObject(definition)) { 23 | definition.name = definition.name || id 24 | definition = this.options._base.extend(definition) 25 | } 26 | if (type === 'directive' && typeof definition === 'function') { 27 | definition = { bind: definition, update: definition } 28 | } 29 | this.options[type + 's'][id] = definition 30 | return definition 31 | } 32 | } 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/runtime/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import Vue from 'core/index' 4 | import { patch } from 'weex/runtime/patch' 5 | import { mountComponent } from 'core/instance/lifecycle' 6 | import platformDirectives from 'weex/runtime/directives/index' 7 | import platformComponents from 'weex/runtime/components/index' 8 | 9 | import { 10 | query, 11 | mustUseProp, 12 | isReservedTag, 13 | isRuntimeComponent, 14 | isUnknownElement 15 | } from 'weex/util/element' 16 | 17 | // install platform specific utils 18 | Vue.config.mustUseProp = mustUseProp 19 | Vue.config.isReservedTag = isReservedTag 20 | Vue.config.isRuntimeComponent = isRuntimeComponent 21 | Vue.config.isUnknownElement = isUnknownElement 22 | 23 | // install platform runtime directives and components 24 | Vue.options.directives = platformDirectives 25 | Vue.options.components = platformComponents 26 | 27 | // install platform patch function 28 | Vue.prototype.__patch__ = patch 29 | 30 | // wrap mount 31 | Vue.prototype.$mount = function ( 32 | el?: any, 33 | hydrating?: boolean 34 | ): Component { 35 | return mountComponent( 36 | this, 37 | el && query(el, this.$document), 38 | hydrating 39 | ) 40 | } 41 | 42 | export default Vue 43 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/TopBanner.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 31 | 32 | 52 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/runtime/modules/attrs.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { extend } from 'shared/util' 4 | 5 | function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { 6 | if (!oldVnode.data.attrs && !vnode.data.attrs) { 7 | return 8 | } 9 | let key, cur, old 10 | const elm = vnode.elm 11 | const oldAttrs = oldVnode.data.attrs || {} 12 | let attrs = vnode.data.attrs || {} 13 | // clone observed objects, as the user probably wants to mutate it 14 | if (attrs.__ob__) { 15 | attrs = vnode.data.attrs = extend({}, attrs) 16 | } 17 | 18 | const supportBatchUpdate = typeof elm.setAttrs === 'function' 19 | const batchedAttrs = {} 20 | for (key in attrs) { 21 | cur = attrs[key] 22 | old = oldAttrs[key] 23 | if (old !== cur) { 24 | supportBatchUpdate 25 | ? (batchedAttrs[key] = cur) 26 | : elm.setAttr(key, cur) 27 | } 28 | } 29 | for (key in oldAttrs) { 30 | if (attrs[key] == null) { 31 | supportBatchUpdate 32 | ? (batchedAttrs[key] = undefined) 33 | : elm.setAttr(key) 34 | } 35 | } 36 | if (supportBatchUpdate) { 37 | elm.setAttrs(batchedAttrs) 38 | } 39 | } 40 | 41 | export default { 42 | create: updateAttrs, 43 | update: updateAttrs 44 | } 45 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/vdom/modules/ref.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { remove, isDef } from 'shared/util' 4 | 5 | export default { 6 | create (_: any, vnode: VNodeWithData) { 7 | registerRef(vnode) 8 | }, 9 | update (oldVnode: VNodeWithData, vnode: VNodeWithData) { 10 | if (oldVnode.data.ref !== vnode.data.ref) { 11 | registerRef(oldVnode, true) 12 | registerRef(vnode) 13 | } 14 | }, 15 | destroy (vnode: VNodeWithData) { 16 | registerRef(vnode, true) 17 | } 18 | } 19 | 20 | export function registerRef (vnode: VNodeWithData, isRemoval: ?boolean) { 21 | const key = vnode.data.ref 22 | if (!isDef(key)) return 23 | 24 | const vm = vnode.context 25 | const ref = vnode.componentInstance || vnode.elm 26 | const refs = vm.$refs 27 | if (isRemoval) { 28 | if (Array.isArray(refs[key])) { 29 | remove(refs[key], ref) 30 | } else if (refs[key] === ref) { 31 | refs[key] = undefined 32 | } 33 | } else { 34 | if (vnode.data.refInFor) { 35 | if (!Array.isArray(refs[key])) { 36 | refs[key] = [ref] 37 | } else if (refs[key].indexOf(ref) < 0) { 38 | // $flow-disable-line 39 | refs[key].push(ref) 40 | } 41 | } else { 42 | refs[key] = ref 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/runtime/recycle-list/render-component-template.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { warn } from 'core/util/debug' 4 | import { handleError } from 'core/util/error' 5 | import { RECYCLE_LIST_MARKER } from 'weex/util/index' 6 | import { createComponentInstanceForVnode } from 'core/vdom/create-component' 7 | import { resolveVirtualComponent } from './virtual-component' 8 | 9 | export function isRecyclableComponent (vnode: VNodeWithData): boolean { 10 | return vnode.data.attrs 11 | ? (RECYCLE_LIST_MARKER in vnode.data.attrs) 12 | : false 13 | } 14 | 15 | export function renderRecyclableComponentTemplate (vnode: MountedComponentVNode): VNode { 16 | // $flow-disable-line 17 | delete vnode.data.attrs[RECYCLE_LIST_MARKER] 18 | resolveVirtualComponent(vnode) 19 | const vm = createComponentInstanceForVnode(vnode) 20 | const render = (vm.$options: any)['@render'] 21 | if (render) { 22 | try { 23 | return render.call(vm) 24 | } catch (err) { 25 | handleError(err, vm, `@render`) 26 | } 27 | } else { 28 | warn( 29 | `@render function not defined on component used in . ` + 30 | `Make sure to declare \`recyclable="true"\` on the component's template.`, 31 | vm 32 | ) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/js/1-5.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author 公众号素燕 3 | * @description 自定义迭代器 4 | * @site 网站:https://lefex.github.io/bat/ 5 | * @xiaoke 前端小课,帮助10W人入门并进阶前端 6 | */ 7 | 8 | class Counter { 9 | constructor(limit) { 10 | this.count = 1; 11 | this.limit = limit; 12 | } 13 | 14 | [Symbol.iterator]() { 15 | let count = 1; 16 | let limit = this.limit; 17 | return { 18 | next() { 19 | if (count <= limit) { 20 | return { 21 | done: false, 22 | value: count++ 23 | }; 24 | } 25 | else { 26 | return { 27 | done: true, 28 | value: undefined 29 | }; 30 | } 31 | }, 32 | return() { 33 | // 提前结束 34 | console.log('Exiting early'); 35 | return { done: true }; 36 | } 37 | } 38 | } 39 | } 40 | 41 | let counter = new Counter(3); 42 | 43 | for(let i of counter) { 44 | console.log(i); 45 | if(i > 1) { 46 | break; 47 | } 48 | } 49 | // 一个 counter 可以多次迭代 50 | for(let i of counter) { 51 | console.log(i); 52 | } -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/server/modules/style.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { escape, noUnitNumericStyleProps } from '../util' 4 | import { hyphenate } from 'shared/util' 5 | import { getStyle } from 'web/util/style' 6 | 7 | export function genStyle (style: Object): string { 8 | let styleText = '' 9 | for (const key in style) { 10 | const value = style[key] 11 | const hyphenatedKey = hyphenate(key) 12 | if (Array.isArray(value)) { 13 | for (let i = 0, len = value.length; i < len; i++) { 14 | styleText += normalizeValue(hyphenatedKey, value[i]) 15 | } 16 | } else { 17 | styleText += normalizeValue(hyphenatedKey, value) 18 | } 19 | } 20 | return styleText 21 | } 22 | 23 | function normalizeValue(key: string, value: any): string { 24 | if ( 25 | typeof value === 'string' || 26 | (typeof value === 'number' && noUnitNumericStyleProps[key]) || 27 | value === 0 28 | ) { 29 | return `${key}:${value};` 30 | } else { 31 | // invalid values 32 | return `` 33 | } 34 | } 35 | 36 | export default function renderStyle (vnode: VNodeWithData): ?string { 37 | const styleText = genStyle(getStyle(vnode, false)) 38 | if (styleText !== '') { 39 | return ` style=${JSON.stringify(escape(styleText))}` 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /docs/vue/index.md: -------------------------------------------------------------------------------- 1 | vue 相关的面试题 2 | 3 | - 聊聊 Vue 的双向数据绑定,Model 如何改变 View,View 又是如何改变 Model 的 4 | - 聊聊 Redux 和 Vuex 的设计思想 5 | - React 和 Vue 的 diff 时间复杂度从 O(n^3) 优化到 O(n) ,那么 O(n^3) 和 O(n) 是如何计算出来的? 6 | - vue 在 v-for 时给每项元素绑定事件需要用事件代理吗?为什么? 7 | - react-router 里的 Link 标签和 a 标签有什么区别 8 | - Vue 的父组件和子组件生命周期钩子执行顺序是什么 9 | - 为什么普通 for 循环的性能远远高于 forEach 的性能,请解释其中的原因。 10 | - redux 为什么要把 reducer 设计成纯函数 11 | - Vue 的响应式原理中 Object.defineProperty 有什么缺陷?为什么在 Vue3.0 采用了 Proxy,抛弃了 Object.defineProperty? 12 | - 双向绑定和 vuex 是否冲突 13 | - 在 Vue 中,子组件为何不可以修改父组件传递的 Prop。如果修改了,Vue 是如何监控到属性的修改并给出警告的。 14 | - 为什么 Vuex 的 mutation 和 Redux 的 reducer 中不能做异步操作? 15 | - Virtual DOM 真的比操作原生 DOM 快吗?谈谈你的想法。 16 | - vue数据绑定的实现原理 17 | - vue computed具体在什么阶段进行的依赖收集,具体的过程详细描述 18 | - vue的生命周期 19 | - vue父子组件通信的方式 20 | - vue eventbus的原理 21 | - vue中可以对对象进行数据监听,如果对于数组中的某个元素能否监听,是如何做到的 22 | - 什么事虚拟dom 23 | - 动态给Vue实例增加属性, this.a = 2 a之前未定义,如何监听a的变化 24 | - 在 vue 中根据索引值修改的数据变动的,是否可以检测到,为什么?如果有这样的场景你怎么处理 25 | - Vue中nextTick 的实现原理 与 node 中的 process.nextTick 的区别 26 | 27 | 28 | 为何组件要从直接产出 html 变成产出 Virtual DOM 呢?其原因是 Virtual DOM 带来了 分层设计,它对渲染过程的抽象,使得框架可以渲染到 web(浏览器) 以外的平台,以及能够实现 SSR 等。 29 | 30 | http://hcysun.me/vue-design/zh/essence-of-comp.html#%E7%BB%84%E4%BB%B6%E7%9A%84%E4%BA%A7%E5%87%BA%E6%98%AF%E4%BB%80%E4%B9%88 31 | 32 | VNode 是真实 DOM 的描述,比如我们可以用如下对象描述一个 div 标签: 33 | 34 | vnode:虚拟 DOM 35 | container:真实 DOM 节点 -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bat", 3 | "version": "1.0.0", 4 | "description": "前端面试", 5 | "main": "index.js", 6 | "directories": { 7 | "doc": "docs", 8 | "example": "examples" 9 | }, 10 | "scripts": { 11 | "dev": "vuepress dev docs", 12 | "build": "vuepress build docs", 13 | "docs": "sh deploy.sh" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/lefex/bat.git" 18 | }, 19 | "keywords": [], 20 | "author": "", 21 | "license": "ISC", 22 | "bugs": { 23 | "url": "https://github.com/lefex/bat/issues" 24 | }, 25 | "homepage": "https://github.com/lefex/bat#readme", 26 | "devDependencies": { 27 | "async-validator": "^1.11.5", 28 | "babel-core": "^6.26.0", 29 | "babel-loader": "^7.1.2", 30 | "babel-plugin-istanbul": "^4.1.6", 31 | "babel-plugin-transform-class-properties": "^6.24.1", 32 | "babel-plugin-transform-decorators-legacy": "^1.3.4", 33 | "babel-plugin-transform-object-assign": "^6.22.0", 34 | "babel-plugin-transform-object-rest-spread": "^6.26.0", 35 | "babel-preset-env": "^1.6.1", 36 | "jest": "^26.4.2", 37 | "vuepress": "^1.5.4", 38 | "webpack": "^4.44.2", 39 | "webpack-cli": "^3.3.12", 40 | "webpack-merge": "^5.1.4" 41 | }, 42 | "dependencies": { 43 | "element-ui": "^2.15.1" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/instance/render-helpers/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { toNumber, toString, looseEqual, looseIndexOf } from 'shared/util' 4 | import { createTextVNode, createEmptyVNode } from 'core/vdom/vnode' 5 | import { renderList } from './render-list' 6 | import { renderSlot } from './render-slot' 7 | import { resolveFilter } from './resolve-filter' 8 | import { checkKeyCodes } from './check-keycodes' 9 | import { bindObjectProps } from './bind-object-props' 10 | import { renderStatic, markOnce } from './render-static' 11 | import { bindObjectListeners } from './bind-object-listeners' 12 | import { resolveScopedSlots } from './resolve-scoped-slots' 13 | import { bindDynamicKeys, prependModifier } from './bind-dynamic-keys' 14 | 15 | export function installRenderHelpers (target: any) { 16 | target._o = markOnce 17 | target._n = toNumber 18 | target._s = toString 19 | target._l = renderList 20 | target._t = renderSlot 21 | target._q = looseEqual 22 | target._i = looseIndexOf 23 | target._m = renderStatic 24 | target._f = resolveFilter 25 | target._k = checkKeyCodes 26 | target._b = bindObjectProps 27 | target._v = createTextVNode 28 | target._e = createEmptyVNode 29 | target._u = resolveScopedSlots 30 | target._g = bindObjectListeners 31 | target._d = bindDynamicKeys 32 | target._p = prependModifier 33 | } 34 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/ThirdCard.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 31 | 32 | 59 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/instance/render-helpers/bind-dynamic-keys.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | // helper to process dynamic keys for dynamic arguments in v-bind and v-on. 4 | // For example, the following template: 5 | // 6 | //
7 | // 8 | // compiles to the following: 9 | // 10 | // _c('div', { attrs: bindDynamicKeys({ "id": "app" }, [key, value]) }) 11 | 12 | import { warn } from 'core/util/debug' 13 | 14 | export function bindDynamicKeys (baseObj: Object, values: Array): Object { 15 | for (let i = 0; i < values.length; i += 2) { 16 | const key = values[i] 17 | if (typeof key === 'string' && key) { 18 | baseObj[values[i]] = values[i + 1] 19 | } else if (process.env.NODE_ENV !== 'production' && key !== '' && key !== null) { 20 | // null is a special value for explicitly removing a binding 21 | warn( 22 | `Invalid value for dynamic directive argument (expected string or null): ${key}`, 23 | this 24 | ) 25 | } 26 | } 27 | return baseObj 28 | } 29 | 30 | // helper to dynamically append modifier runtime markers to event names. 31 | // ensure only append when value is already string, otherwise it will be cast 32 | // to string and cause the type check to miss. 33 | export function prependModifier (value: any, symbol: string): any { 34 | return typeof value === 'string' ? symbol + value : value 35 | } 36 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/util/lang.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | /** 4 | * unicode letters used for parsing html tags, component names and property paths. 5 | * using https://www.w3.org/TR/html53/semantics-scripting.html#potentialcustomelementname 6 | * skipping \u10000-\uEFFFF due to it freezing up PhantomJS 7 | */ 8 | export const unicodeRegExp = /a-zA-Z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD/ 9 | 10 | /** 11 | * Check if a string starts with $ or _ 12 | */ 13 | export function isReserved (str: string): boolean { 14 | const c = (str + '').charCodeAt(0) 15 | return c === 0x24 || c === 0x5F 16 | } 17 | 18 | /** 19 | * Define a property. 20 | */ 21 | export function def (obj: Object, key: string, val: any, enumerable?: boolean) { 22 | Object.defineProperty(obj, key, { 23 | value: val, 24 | enumerable: !!enumerable, 25 | writable: true, 26 | configurable: true 27 | }) 28 | } 29 | 30 | /** 31 | * Parse simple path. 32 | */ 33 | const bailRE = new RegExp(`[^${unicodeRegExp.source}.$_\\d]`) 34 | export function parsePath (path: string): any { 35 | if (bailRE.test(path)) { 36 | return 37 | } 38 | const segments = path.split('.') 39 | return function (obj) { 40 | for (let i = 0; i < segments.length; i++) { 41 | if (!obj) return 42 | obj = obj[segments[i]] 43 | } 44 | return obj 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /docs/dsa/index.md: -------------------------------------------------------------------------------- 1 | # 数据结构和算法 2 | 3 | - 用 JavaScript 写一个函数,输入 int 型,返回整数逆序后的字符串。如:输入整型 1234,返回字符串“4321”。要求必须使用递归函数调用,不能用全局变量,输入函数必须只有一个参数传入,必须返回字符串。 4 | - 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2。请找出这两个有序数组的中位数。要求算法的时间复杂度为 O(log(m+n))。 5 | - 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数。 6 | - 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。 7 | - 打印出 1 - 10000 之间的所有对称数,例如:121、1331 等 8 | - 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。 9 | - 数组里面有10万个数据,取第一个元素和第10万个元素的时间相差多少 10 | - 如何把一个字符串的大小写取反(大写变小写小写变大写),例如 ’AbC' 变成 'aBc' 。 11 | - 随机生成一个长度为 10 的整数类型的数组,例如 [2, 10, 3, 4, 5, 11, 10, 11, 20],将其排列成一个新数组,要求新数组形式如下,例如 [[2, 3, 4, 5], [10, 11], [20]]。 12 | - 给定两个数组,写一个方法来计算它们的交集。 13 | - 冒泡排序如何实现,时间复杂度是多少, 还可以如何改进? 14 | - 使用 sort() 对数组 [3, 15, 8, 29, 102, 22] 进行排序,输出结果 15 | - 两个数组合并成一个数组 16 | 请把两个数组 ['A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D1', 'D2'] 和 ['A', 'B', 'C', 'D'],合并为 ['A1', 'A2', 'A', 'B1', 'B2', 'B', 'C1', 'C2', 'C', 'D1', 'D2', 'D']。 17 | - var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10]; 18 | 编写一个程序将数组扁平化去并除其中重复部分数据,最终得到一个升序且不重复的数组 19 | - 给定一个sum 检验一棵树中,是否存在一条路径和为sum,输出该路径 20 | - 写一个函数,给定一棵树,输出这棵树的深度 21 | - 写一个函数,给定一个url和最大深度maxdeep,输出抓取当前url及其子链接深度范围内的所有图片 22 | - 写一个函数,给定nodes=[],每一个节点拥有id,name,parentid,输出一个属性列表的展示(涉及dom操作) 23 | - 实现一个NumberStack,实现pop,push,max(n)方法,max(n)返回第n大的数,max(n)需要 O(1)的时间复杂度 24 | - 给定一个html,输出其中包含的html标签数量,可以用domapi 注意iframe 25 | - 写一个数组方法,打乱整个数组顺序,并且每个数字落在各个位置的概率相同 26 | - - 给定 n 个 {x, y, w, h}的盒子 按需排列,左上聚拢(层叠后的max(h)*max(w)最小),求给一个{w,h},输出放置的位置 -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/compiler/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { genStaticKeys } from 'shared/util' 4 | import { createCompiler } from 'compiler/index' 5 | 6 | import modules from './modules/index' 7 | import directives from './directives/index' 8 | 9 | import { 10 | isUnaryTag, 11 | mustUseProp, 12 | isReservedTag, 13 | canBeLeftOpenTag, 14 | getTagNamespace 15 | } from '../util/element' 16 | 17 | export const baseOptions: WeexCompilerOptions = { 18 | modules, 19 | directives, 20 | isUnaryTag, 21 | mustUseProp, 22 | canBeLeftOpenTag, 23 | isReservedTag, 24 | getTagNamespace, 25 | preserveWhitespace: false, 26 | recyclable: false, 27 | staticKeys: genStaticKeys(modules) 28 | } 29 | 30 | const compiler = createCompiler(baseOptions) 31 | 32 | export function compile ( 33 | template: string, 34 | options?: WeexCompilerOptions 35 | ): WeexCompiledResult { 36 | let generateAltRender = false 37 | if (options && options.recyclable === true) { 38 | generateAltRender = true 39 | options.recyclable = false 40 | } 41 | const result = compiler.compile(template, options) 42 | 43 | // generate @render function for 44 | if (options && generateAltRender) { 45 | options.recyclable = true 46 | // disable static optimizations 47 | options.optimize = false 48 | const { render } = compiler.compile(template, options) 49 | result['@render'] = render 50 | } 51 | return result 52 | } 53 | -------------------------------------------------------------------------------- /main/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /main/src/topic/eventLoop.ts: -------------------------------------------------------------------------------- 1 | export function runEventLoop() { 2 | 3 | type Task = () => (void); 4 | const microtaskQueue: Task[] = []; 5 | const macrotaskQueue: Task[] = []; 6 | 7 | function queueMicrotask(task: Task) { 8 | microtaskQueue.push(task); 9 | } 10 | 11 | function queueMacrotask(task: Task) { 12 | macrotaskQueue.push(task); 13 | } 14 | 15 | function runMicrotasks() { 16 | while (microtaskQueue.length > 0) { 17 | const task = microtaskQueue.shift(); 18 | task && task(); 19 | } 20 | } 21 | 22 | function runMacrotasks() { 23 | while (macrotaskQueue.length > 0) { 24 | const task = macrotaskQueue.shift(); 25 | task && task(); 26 | } 27 | } 28 | 29 | function eventLoop() { 30 | while (true) { 31 | // Run all microtasks before running any macrotasks 32 | runMicrotasks(); 33 | 34 | // If there are no more tasks to execute, wait for new tasks to arrive 35 | if (microtaskQueue.length === 0 && macrotaskQueue.length === 0) { 36 | setTimeout(eventLoop, 0); 37 | return; 38 | } 39 | 40 | // Run the oldest macrotask 41 | runMacrotasks(); 42 | } 43 | } 44 | 45 | // Example usage 46 | queueMicrotask(() => console.log("Microtask 1")); 47 | queueMicrotask(() => console.log("Microtask 2")); 48 | queueMacrotask(() => console.log("Macrotask 1")); 49 | queueMacrotask(() => console.log("Macrotask 2")); 50 | 51 | eventLoop(); 52 | } -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/runtime/modules/events.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { updateListeners } from 'core/vdom/helpers/update-listeners' 4 | 5 | let target: any 6 | 7 | function createOnceHandler (event, handler, capture) { 8 | const _target = target // save current target element in closure 9 | return function onceHandler () { 10 | const res = handler.apply(null, arguments) 11 | if (res !== null) { 12 | remove(event, onceHandler, capture, _target) 13 | } 14 | } 15 | } 16 | 17 | function add ( 18 | event: string, 19 | handler: Function, 20 | capture: boolean, 21 | passive?: boolean, 22 | params?: Array 23 | ) { 24 | if (capture) { 25 | console.log('Weex do not support event in bubble phase.') 26 | return 27 | } 28 | target.addEvent(event, handler, params) 29 | } 30 | 31 | function remove ( 32 | event: string, 33 | handler: any, 34 | capture: any, 35 | _target?: any 36 | ) { 37 | (_target || target).removeEvent(event) 38 | } 39 | 40 | function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) { 41 | if (!oldVnode.data.on && !vnode.data.on) { 42 | return 43 | } 44 | const on = vnode.data.on || {} 45 | const oldOn = oldVnode.data.on || {} 46 | target = vnode.elm 47 | updateListeners(on, oldOn, add, remove, createOnceHandler, vnode.context) 48 | target = undefined 49 | } 50 | 51 | export default { 52 | create: updateDOMListeners, 53 | update: updateDOMListeners 54 | } 55 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/weex/util/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | declare var document: WeexDocument; 3 | 4 | import { warn } from 'core/util/index' 5 | 6 | export const RECYCLE_LIST_MARKER = '@inRecycleList' 7 | 8 | // Register the component hook to weex native render engine. 9 | // The hook will be triggered by native, not javascript. 10 | export function registerComponentHook ( 11 | componentId: string, 12 | type: string, // hook type, could be "lifecycle" or "instance" 13 | hook: string, // hook name 14 | fn: Function 15 | ) { 16 | if (!document || !document.taskCenter) { 17 | warn(`Can't find available "document" or "taskCenter".`) 18 | return 19 | } 20 | if (typeof document.taskCenter.registerHook === 'function') { 21 | return document.taskCenter.registerHook(componentId, type, hook, fn) 22 | } 23 | warn(`Failed to register component hook "${type}@${hook}#${componentId}".`) 24 | } 25 | 26 | // Updates the state of the component to weex native render engine. 27 | export function updateComponentData ( 28 | componentId: string, 29 | newData: Object | void, 30 | callback?: Function 31 | ) { 32 | if (!document || !document.taskCenter) { 33 | warn(`Can't find available "document" or "taskCenter".`) 34 | return 35 | } 36 | if (typeof document.taskCenter.updateData === 'function') { 37 | return document.taskCenter.updateData(componentId, newData, callback) 38 | } 39 | warn(`Failed to update component data (${componentId}).`) 40 | } 41 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/server/bundle-renderer/source-map-support.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | const SourceMapConsumer = require('source-map').SourceMapConsumer 4 | 5 | const filenameRE = /\(([^)]+\.js):(\d+):(\d+)\)$/ 6 | 7 | export function createSourceMapConsumers (rawMaps: Object) { 8 | const maps = {} 9 | Object.keys(rawMaps).forEach(file => { 10 | maps[file] = new SourceMapConsumer(rawMaps[file]) 11 | }) 12 | return maps 13 | } 14 | 15 | export function rewriteErrorTrace (e: any, mapConsumers: { 16 | [key: string]: SourceMapConsumer 17 | }) { 18 | if (e && typeof e.stack === 'string') { 19 | e.stack = e.stack.split('\n').map(line => { 20 | return rewriteTraceLine(line, mapConsumers) 21 | }).join('\n') 22 | } 23 | } 24 | 25 | function rewriteTraceLine (trace: string, mapConsumers: { 26 | [key: string]: SourceMapConsumer 27 | }) { 28 | const m = trace.match(filenameRE) 29 | const map = m && mapConsumers[m[1]] 30 | if (m != null && map) { 31 | const originalPosition = map.originalPositionFor({ 32 | line: Number(m[2]), 33 | column: Number(m[3]) 34 | }) 35 | if (originalPosition.source != null) { 36 | const { source, line, column } = originalPosition 37 | const mappedPosition = `(${source.replace(/^webpack:\/\/\//, '')}:${String(line)}:${String(column)})` 38 | return trace.replace(filenameRE, mappedPosition) 39 | } else { 40 | return trace 41 | } 42 | } else { 43 | return trace 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/core/instance/render-helpers/render-list.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { isObject, isDef, hasSymbol } from 'core/util/index' 4 | 5 | /** 6 | * Runtime helper for rendering v-for lists. 7 | */ 8 | export function renderList ( 9 | val: any, 10 | render: ( 11 | val: any, 12 | keyOrIndex: string | number, 13 | index?: number 14 | ) => VNode 15 | ): ?Array { 16 | let ret: ?Array, i, l, keys, key 17 | if (Array.isArray(val) || typeof val === 'string') { 18 | ret = new Array(val.length) 19 | for (i = 0, l = val.length; i < l; i++) { 20 | ret[i] = render(val[i], i) 21 | } 22 | } else if (typeof val === 'number') { 23 | ret = new Array(val) 24 | for (i = 0; i < val; i++) { 25 | ret[i] = render(i + 1, i) 26 | } 27 | } else if (isObject(val)) { 28 | if (hasSymbol && val[Symbol.iterator]) { 29 | ret = [] 30 | const iterator: Iterator = val[Symbol.iterator]() 31 | let result = iterator.next() 32 | while (!result.done) { 33 | ret.push(render(result.value, ret.length)) 34 | result = iterator.next() 35 | } 36 | } else { 37 | keys = Object.keys(val) 38 | ret = new Array(keys.length) 39 | for (i = 0, l = keys.length; i < l; i++) { 40 | key = keys[i] 41 | ret[i] = render(val[key], key, i) 42 | } 43 | } 44 | } 45 | if (!isDef(ret)) { 46 | ret = [] 47 | } 48 | (ret: any)._isVList = true 49 | return ret 50 | } 51 | -------------------------------------------------------------------------------- /docs/vue/vue-2.6.0/src/platforms/web/server/directives/model.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { looseEqual, looseIndexOf } from 'shared/util' 4 | 5 | // this is only applied for