简体   繁体   English

basil.js中b.startsWith()的语法

[英]Syntax of b.startsWith() in basil.js

I was wondering how the syntax of the b.startsWith() function in basil.js is supposed to look. 我想知道如何看看basil.js中b.startsWith()函数的语法。

I want to check all words of a text to see, if they start with the string 'some' (like 'sometimes', 'something', 'someone', 'somewhere' etc.). 我想查看文本的所有单词,如果它们以字符串'some'开头(如'有时','某事','某人','某处'等)。

So, I create a variable that passes on every word of my text to the b.startsWith() function. 所以,我创建了一个变量,它将我的文本的每个单词传递给b.startsWith()函数。

When I put the string I am searching for in the brackets ( b.startsWith(some) ), then where exactly will I have to put the variable that will be checked if it starts with my 'some'-string? 当我在括号中搜索我正在搜索的字符串(b.startsWith(some))时,如果它以我的'some'字符串开头,我将在哪里准备将要检查的变量?

It looks like their documentation has some errors. 看起来他们的文档有一些错误。 It shows the function signature as you have described: 它显示了您所描述的函数签名:

b.startsWith(str)

But if you look at the code where the function is defined it looks like this: 但是如果你看一下定义函数的代码 ,它看起来像这样:

var startsWith = pub.startsWith = function(str, prefix) {
  return str.indexOf(prefix) === 0;
};

The first argument is the string to search through, and the second argument is the string to search for. 第一个参数是要搜索的字符串,第二个参数是要搜索的字符串。

There was indeed an error in our documentation. 我们的文档确实存在错误。 It's fixed now, thanks for letting us know. 它已经修好了,感谢您告诉我们。

So you can use it as 所以你可以用它作为

var trueOrFalse = b.startsWith( yourWord, yourSearchToken );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM