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')
相关推荐
空中海18 分钟前
第一章:Vue 基础与模板语法
前端·javascript·vue.js
mCell23 分钟前
为什么我不建议初学者一上来就用框架学 Agent
javascript·langchain·agent
每天吃饭的羊32 分钟前
水平,垂直居中
前端·javascript·html
我爱cope1 小时前
【从0开始学设计模式-12| 代理模式】
设计模式·代理模式
thankseveryday1 小时前
Three.js 把 Blender 绘制的曲线(Bezier / 曲线) 导入 Three.js 并作为运动路径 / 动画路径使用
开发语言·javascript·blender
geovindu2 小时前
go: Composite Pattern
设计模式·golang·组合模式
空中海2 小时前
第四章:Vue Router
前端·javascript·vue.js
竹林8182 小时前
从零集成RainbowKit:我如何在一个周末搞定多链钱包连接并填平三个大坑
前端·javascript
2601_953465612 小时前
M3U8 在线播放器:无需安装,一键调试 HLS 直播流
开发语言·前端·javascript·开发工具·m3u8·m3u8在线播放