zoukankan      html  css  js  c++  java
  • ↗☻【编写可维护的JavaScript #BOOK#】第3章 语句和表达式

    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <script>
            /*
             * for 数组
             * for-in 对象
             * 避免使用continue,使用条件语句替代
             */
    
            switch ('1') {
                case '1':
                case '2':
                    console.log('ca');
                    break;
                default:
                    console.log('caca');
            }
    
            /*
             * 通过with可以用局部变量和函数的形式来访问特定对象的属性和方法,
             * 这样就可以将对象前缀统统省略掉
             * 不推荐使用
             */
             var book = {
                 title: 'Maintainable JavaScript',
                 author: 'Nicholas C. Zakes'
             }
             var message = 'The book is '
             with (book) {
                 message += title
                 message += ' by ' + author
             }
             console.log(message)
    
             /*
              * for-in不仅遍历对象的实例属性,同样还遍历从原型继承而来的属性
              * Crockford的编程规范要求所有的for-in循环都必须使用hasOwnProperty()
              */
             var prop
             for (prop in book) {
                 if (book.hasOwnProperty(prop)) {
                     console.log('Property name is ' + prop)
                     console.log('Property value is ' + book[prop])
                 }
             }
        </script>
    </body>
    </html>
  • 相关阅读:
    C# 线程之间切换
    工厂方法(创建型)
    单例模式(创建型)
    HTTP请求超时
    命令模式
    Asp.Net Core EF Migrations(二)
    Asp.Net Core EF Migrations
    Vue父子组件之间的通讯(学习笔记)
    数组的方法(笔记)
    Vue-router入门
  • 原文地址:https://www.cnblogs.com/jzm17173/p/3133488.html
Copyright © 2011-2022 走看看