zoukankan      html  css  js  c++  java
  • node基础04:模块调用

    1.模块调用

      node遵循AMD规范

    //server.js
    var http = require("http");
    var Teacher = require("./teacher");
    http.createServer(function(request, response){
        response.writeHead(200, {"Content-Type":"text/html; charset=uf-8"});
        if (request.url!=="/favicon.ico") {
            let teacher = new Teacher(1, 'gaoxiong', 24);
            teacher.job();
            response.end();
        }
    }).listen(8000);
    console.log('Server running at http://127.0.0.1:8000/');
    //user.js
    function User(id, name, age){
        this.id = id;
        this.name = name;
        this.age = age;
        this.job = function(){
            console.log('learning');
        }
    }
    module.exports = User;
    //teacher.js
    var User = require("./user");
    function Teacher(id, name, age){
        User.apply(this, [id, name, age]);
        this.job = function(){
            console.log('teaching:'+this.name);
        } 
    }
    module.exports = Teacher;
  • 相关阅读:
    IDEA
    elasticsearch java api
    Java-HttpUtil
    spring集成mybatis-plus
    linux语句速查
    linux切换jdk
    《Java并发编程实战》读书笔记
    设计模式六大原则
    Linux 启动管理
    Linux 日志管理
  • 原文地址:https://www.cnblogs.com/noper/p/6243764.html
Copyright © 2011-2022 走看看