zoukankan      html  css  js  c++  java
  • 一个面向对象的JS例子,很好的支持了开闭原则(不要重复你昨天的代码)

    <script type="text/javascript">
        //一个面向对象的JS例子,很好的支持了开闭原则
        function HtmlControl(options) {//定义一个方法
            var el = options.element;
            el.style.width = options.width;
            el.style.height = options.height;
            el.style.top = options.top;
            el.style.background = options.background;
        }
     
        var option = { //为方法定义一个参数对象
            element: document.getElementById('test'),
            left: 50,
            top: 0,
             100,
            height: 200,
            background: '#f00'
        }
        option.background = '#ff0'; //对参数对象进行扩展
     
        HtmlControl(option); //调用
    </script>
  • 相关阅读:
    命名空间 和 class_exist() 问题
    浏览器中打开文件
    memcach 安装
    MySQL事务机制
    Xcode10更新报错:library not found for -lstdc++.6.0.9
    appium-chromedriver@3.0.1 npm ERR! code ELIFECYCLE npm ERR! errno 1
    npm audit fix
    使用WebStorm/IDEA上传本地项目到GitHub
    vue-cli(vue脚手架)超详细教程
    [Swift 开发] 使用闭包传值(typealias)
  • 原文地址:https://www.cnblogs.com/lori/p/2178332.html
Copyright © 2011-2022 走看看