zoukankan      html  css  js  c++  java
  • node学习第三天(1)

    今天学习了,node调用模块的方法

    node调用模块

    要调用模块的js

     1 var http = require("http");
     2 
     3 var Teacher = require("./Teacher");
     4 
     5 http.createServer(function(request,response)
     6 {
     7 
     8   response.writeHead(200,{'Content-Type':'text/html;charset=utf-8'});
     9 
    10   if(request.url!=='/favicon.ico'){
    11 
    12       teacher = new Teacher(1,"张三老师",30);
    13 
    14       teacher.enter();
    15 
    16       teacher.teach(response);
    17 
    18      response.end();
    19 
    20   } 
    21 
    22 }).listen(8000);
    23 
    24 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.enter=function(){
          console.log(this.name+"进入图书馆");
        }
        
    }
    
    module.exports = User;

    Teacher.js

     1 var User =require("./User");
     2 function Teacher(id,name,age){
     3 //Teacher通过apply继承User的属性
     4   User.apply(this,[id,name,age]);
     5   this.teach=function(res){
     6      res.write(this.name+"教学");
     7   }
     8 }
     9 
    10 module.exports = Teacher;

    以上是源码。

  • 相关阅读:
    css 定位
    css inline忽略宽和高
    css clear属性
    关系型数据库与nosql
    链接标签<a>的css定义规则
    1em=16px
    text-align的justify属性
    2393Cirno的完美算数教室 容斥
    bzoj4665小w的喜糖 dp+容斥
    bzoj4558[JLoi2016]方 容斥+count
  • 原文地址:https://www.cnblogs.com/jolee/p/6020430.html
Copyright © 2011-2022 走看看