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;
  • 相关阅读:
    mongodb 添加用户
    mongo 安装
    python 操作redis
    python 安装 redis
    redis 命令文档网址
    redis 事务
    Redis key命令
    手动卸载的vs2010
    个人封装JavaScript函数
    女学-温砚如老师的人生女学
  • 原文地址:https://www.cnblogs.com/noper/p/6243764.html
Copyright © 2011-2022 走看看