2016-05-13 78 views
1

对不起,如果这是一个愚蠢的问题,但我一直在寻找并找不到答案。我是Mongoose的新手,一般编程,我一直在阅读API文档,以更好地理解Mongoose的功能。在文档中,他们有两种访问对象属性的方法,通过“点”符号和“#”符号?我不确定“#”代表什么。感谢您的时间。Mongoose API文档中的#是什么?

回答

3

这纯粹是一个文档件事:#通常用于表示一个实例方法.一个类方法(也称为静态方法)。

例如:

  • Schema#set:这意味着类Schema实例将有一个称为set()方法。例如:

    var dogSchema = new Schema(...); // create an instance of `Schema` 
    dogSchema.set('strict');   // call the instance method `set()` 
    

    注意,你实际上并不在这里使用的#字符,它仍然是一个.在实际的代码。

  • Schema.indexTypes:这意味着类Schema本身有一个方法indexTypes()。例如:

    var types = Schema.indexTypes(); // get the list of index types 
    

更多关于实例和类/ JavaScript中静态方法可以发现here

+0

非常感谢您的解释和链接。对此,我真的非常感激。 – cderleth84