zoukankan      html  css  js  c++  java
  • exports

    暴露函数

    var bar = require("./bar.js");
    var msg = "你好";
    var info = "呵呵";
    
    function showInfo(){
        console.log(info);
    }
    
    exports.msg = msg;
    exports.info = info;
    exports.showInfo = showInfo;

    使用

    var foo = require("./test/foo.js");
    
    console.log(foo.msg);
    console.log(foo.info);
    foo.showInfo();

    暴露类

    function People(name,sex,age){
        this.name = name;
        this.sex = sex;
        this.age = age;
    }
    
    People.prototype = {
        sayHello : function(){
            console.log(this.name + this.sex + this.age);
        }
    }
    
    //此时,People就被视为构造函数,可以用new来实例化了。
    module.exports = People;

    使用

    var People = require("./test/People.js");
    var xiaoming = new People("小明","男","12");
    xiaoming.sayHello();
  • 相关阅读:
    精妙SQL语句介绍
    ASP判断文件地址是否有效
    将源代码清空,这样别人就看不到源码了
    部署
    sublime
    vscode
    android node
    mac开启热点
    微信
    常见问题
  • 原文地址:https://www.cnblogs.com/Erick-L/p/7768946.html
Copyright © 2011-2022 走看看