JS模块化

DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Documenttitle>
head>

<body>
    <p>2p>
    <script src="myScript.js">script>
    <script>
        person.printName();
    script>
body>

html>
var person = (function () {
    var name = 'vicin';
    var age = 28;
    var printName = function () {
        console.log(name)
    }
    var printAge = function () {
        console.log(age);
    }
    return {
        printName: printName,
        printAge: printAge
    }
})();

输出:vicin

你可能感兴趣的:(JS模块化)