函数声明与函数表达式

ddd

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<script>
//    1.constructor指向不同
//    var sayHi = function () {
//
//    };
//
//    function sayHello(){
//
//    }

//    console.log(sayHi.prototype);       //constructor指向匿名函数
//    console.log(sayHello.prototype);    //constructor指向自己
</script>
<script>
//    2.调用顺序
//    sayHi();      //error!
//    var sayHi = function () {
//        alert("Hi");
//    };
//
//    sayHi();        //必须在之后条用
//
//    sayHello();     //调用的位置无关紧要
//    function sayHello(){
//        alert("Hello");
//    }
</script>
<script>
//    3.在模拟作用于中,函数表达式是全局的,函数声明是局部的
//(function () {
//    sayHi = function () {
//        alert("Hi");
//    }
//
//    function sayHello(){
//        alert("Hello");
//    }
//
//})()

//    sayHi();        //alert "Hi"
//    sayHello();     //error!
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/masita/p/5120313.html