我正在使用Parse.com Cloud Code尝试单数化单词。
我发现了String类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
关于javascript - 调用扩展字符串对象中定义的JavaScript函数获取错误对象没有方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30679225/