【问题标题】:Newbie problems with Node, Mongo, and MongooseNode、Mongo 和 Mongoose 的新手问题
【发布时间】:2011-09-03 04:20:09
【问题描述】:

我正在尝试通过查看来自 GitHub 的代码来学习如何使用 Node、Mongoose 和 Mongo。

这一行的目的是什么:

PostProvider = function(){};

来自:https://github.com/cmarin/MongoDB-Node-Express-Blog/blob/master/postprovider.js

对我来说,这似乎是一个空函数。

【问题讨论】:

    标签: mongodb node.js express mongoose


    【解决方案1】:

    为了模拟javascript中的“类概念”,我们有3 ways。其中一种方法是使用原型功能。 Apple 类的示例:

    function Apple (type) {
        this.type = type;
        this.color = "red";
    }
    
    Apple.prototype.getInfo = function() {
        return this.color + ' ' + this.type + ' apple';
    };
    

    在您的示例中, PostProvider 函数没有属性。所以,“cmarin”声明了一个空函数:

    PostProvider = function() {};
    

    并添加一些方法:

    • PostProvider.prototype.findAll
    • PostProvider.prototype.findById

    【讨论】:

      猜你喜欢
      • 2017-02-07
      • 2017-10-12
      • 1970-01-01
      • 2021-08-22
      • 1970-01-01
      • 2016-11-13
      • 2021-06-18
      • 2018-12-13
      • 2013-10-16
      相关资源
      最近更新 更多