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')
相关推荐
二哈喇子!6 小时前
BOM模型
开发语言·前端·javascript·bom
二哈喇子!6 小时前
Vue2 监听器 watcher
前端·javascript·vue.js
摘星编程7 小时前
在OpenHarmony上用React Native:ActionSheet确认删除
javascript·react native·react.js
2501_944521597 小时前
Flutter for OpenHarmony 微动漫App实战:推荐动漫实现
android·开发语言·前端·javascript·flutter·ecmascript
Yu_Lijing7 小时前
基于C++的《Head First设计模式》笔记——模式合作
c++·笔记·设计模式
S-X-S8 小时前
常用设计模式+集成websocket
websocket·设计模式
Amumu121388 小时前
Vue核心(三)
前端·javascript·vue.js
Irene19919 小时前
JavaScript中,为什么需要手动清理事件
javascript·手动清理事件监听器
摘星编程9 小时前
OpenHarmony环境下React Native:Zustand持久化存储
javascript·react native·react.js
2501_944521599 小时前
Flutter for OpenHarmony 微动漫App实战:图片加载实现
android·开发语言·前端·javascript·flutter·php