js设计模式:建造者模式

作用:

将众多功能独立封装,然后用一个大类将其全部收纳,形成一个完整的功能

这个是很常见的设计模式

示例:

javascript 复制代码
        function render(h){
        }

        function h(){

        }

        function $mount(dom){
       console.log(dom,'绑定的根节点')
       console.log(this,'this是vue实例')
        }

        function use(plugin){
        
        }

        function $attr(){

        }

        function $emit(){

        }

        class Vue{
         constructor(vue){
            this.render = render
            this.$mount = $mount
            this.use = use
         }
         attr = $attr
         $emit = $emit
         static self = function(){
            return '看不到我'
         }
        }

        //使用
        let vueComponent1 =  new Vue({
            beforeCreate(){},
            created(){},
            render:h=>h()
        })

        console.log(vueComponent1,'vue组件实例')
        vueComponent1.$mount('#app')
相关推荐
Mintopia6 分钟前
B 样条曲线:计算机图形学里的 “曲线魔术师”
前端·javascript·计算机图形学
Mintopia12 分钟前
Three.js 3D 世界中的噪声运动:当数学与像素共舞
前端·javascript·three.js
来碗疙瘩汤15 分钟前
使用 Three.js 与 CSS3DRenderer 在 Vue3 中加载网页为 3D 模型
前端·javascript
打野赵怀真17 分钟前
在TypeScript中装饰器有哪些应用场景?
前端·javascript
destinying19 分钟前
vite学习笔记
前端·javascript
LRH20 分钟前
JS基础 - 手写数组扁平化函数
前端·javascript
FogLetter23 分钟前
从零到一实现流式输出:SSE技术在前端应用中的魔法时刻
前端·javascript
G等你下课23 分钟前
如何进行DOM操作?
javascript·html
哈里谢顿27 分钟前
python 设计模式
设计模式
OpenC++40 分钟前
【C++】备忘录模式
c++·设计模式·备忘录模式