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')
相关推荐
刀法如飞5 小时前
开箱即用的 DDD(领域驱动设计)工程脚手架,基于 Spring Boot 4.0.1 和 Java 21
java·spring boot·mysql·spring·设计模式·intellij-idea
哈__6 小时前
React Native 鸿蒙跨平台开发:PixelRatio 像素适配
javascript·react native·react.js
用户6387994773057 小时前
每组件(Per-Component)与集中式(Centralized)i18n
前端·javascript
DarkLONGLOVE7 小时前
Vue组件使用三步走:创建、注册、使用(Vue2/Vue3双版本详解)
前端·javascript·vue.js
DarkLONGLOVE7 小时前
手把手教你玩转Vue组件:创建、注册、使用三步曲!
前端·javascript·vue.js
冴羽8 小时前
2026 年前端必须掌握的 4 个 CSS 新特性!
前端·javascript·css
狗头大军之江苏分军8 小时前
告别旧生态:Ant Design 6 不再支持 IE 与现代前端趋势解读
前端·javascript·后端
Highcharts.js9 小时前
Highcharts Grid 表格/网格安装 |官方安装文档说明
开发语言·javascript·表格组件·highcharts·官方文档·安装说明·网格组件
GISer_Jing9 小时前
AI Agent 人类参与HITL与知识检索RAG
人工智能·设计模式·aigc
3824278279 小时前
表单提交验证:onsubmit与return详解
前端·javascript·html