• Node.js学习



    创建模块

    当前目录:hello.js, main.js

    // hello.js
    exports.world = function() {      // exports 对象把 world 作为模块的访问接口
        console.log("Hello World!");
    }
    
    
    // main.js
    var hello = require('./hello');
    hello.world();

    //hello.js 
    function Hello() {                //也可以把一个对象封装到模块中
    	var name; 
    	this.setName = function(thyName) { 
    		name = thyName; 
    	}; 
    	this.sayHello = function() { 
    		console.log('Hello ' + name); 
    	}; 
    }; 
    module.exports = Hello;
     

    模块加载流程


     

    KEEP LEARNING!
  • 相关阅读:
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    Windows邮件添加QQ邮箱
  • 原文地址:https://www.cnblogs.com/roronoa-sqd/p/5397168.html
Copyright © 2020-2023  润新知