解析平台-调用JavaScript函数定义在一个扩展字符串对象得到错误对象没有方法

parse platform - calling JavaScript function defined in an extended String objects gets error object has no method

本文关键字:对象 字符串 扩展 一个 有方法 错误 调用 平台 JavaScript 函数 定义      更新时间:2023-09-26

我正在使用Parse.com云代码,我试图将单词单数。我发现了字符串类Inflection-js的扩展,它使用如下函数:

String.singularize(singular) 

但是当我运行它时,我得到:

Result: TypeError: Object doors has no method 'singularize'

下面是我如何使用Inflection-js

var express = require('express');
require('cloud/inflection.js');
Parse.Cloud.beforeSave("Comment", function(request, response) {
    var test = "doors";
    console.log(test.singularize());
    //...
}

问题是Inflection-js不支持AMD,所以它不能与RequireJS一起工作,使用它的这个端口代替:https://github.com/simonwex/inflection-js