zoukankan      html  css  js  c++  java
  • JS高级 — 函数中的this指向问题

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset="utf-8">
     5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     6 <title>函数的角色</title>
     7 </head>
     8 <body>
     9     <script>
    10         // 二、函数声明 & 函数表达式的区别
    11         // 函数声明
    12         // if (true) {
    13         //     function f1(){
    14         //         console.log("jjjjjjjj");
    15         //     }
    16         // } else{
    17         //     function f1() {
    18         //         console.log("ggggggg");
    19         //     }
    20         // }
    21         // f1(); //jjjjjjj
    22         
    23         var ff;
    24         if (true) {
    25             ff = function(){
    26                 console.log("jjjjjjjj");
    27             }
    28         } else {
    29             ff = function() {
    30                 console.log("ggggggg");
    31             }
    32         }
    33         ff();
    34 // 函数声明如果放在if-else语句中 在IE8的浏览器中会出现问题
    35 // 建议使用 函数表达式
    36 
    37         // 一、函数的角色
    38         // 1、函数的声明
    39         function fun(){
    40             console.log("我是函数声明!");
    41         }
    42         // 使用
    43         fun(); 
    44         // 2、函数表达式
    45         var ff = function(){
    46             console.log("我是函数表达式!");
    47         };
    48         // 使用
    49         ff();  
    50         // 二、函数声明核函数表达式的区别
    51         
    52     </script>
    53 </body>
    54 </html>

  • 相关阅读:
    multiprocessing模块
    socket&socketserver网络编程
    collections模块
    socket模块
    网络基础知识
    迭代器,生成器,列表推导式,生成器表达式
    logging模块
    Module
    页面中公用的全选按钮,单选按钮组件的编写
    ajax
  • 原文地址:https://www.cnblogs.com/sylys/p/11578517.html
Copyright © 2011-2022 走看看