javascript - 什么时候字符串不是字符串?当它没有 includes() 方法时?

标签 javascript string coffeescript

我正在尝试编写一个简单的 javascript(以及 coffeescript)测试并且有一些令人困惑的东西:

dclib.appendVarToUrl = (base, k, v) ->
  check base, String
  console.log("base is a:", typeof(base))
  if base.includes("?")
     ... 

// called with
dclib.appendVarToUrl("some/url", "score", 5)

给我:

base is a: string
TypeError: Object some/url has no method 'includes'

那么为什么 String 没有 .includes() 方法呢? 这个 coffeescript 是否以一种奇怪的方式包装了一个对象?

最佳答案

啊哈,看起来我的浏览器支持这个作为 ES6 方法,但我使用的节点版本不支持。我在服务器上运行单元测试,而该方法在客户端运行良好。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes

This is an experimental technology, part of the ECMAScript 6 (Harmony) proposal.

关于javascript - 什么时候字符串不是字符串?当它没有 includes() 方法时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29089959/

相关文章:

javascript - 动态加载javascript失败,但innerHTML却失败

javascript - 像 StackOverflow 标签选择器一样的投递箱

javascript - 在firefox中重载JS的对象原型(prototype)

c - 替换字符串 malloc 中的字符

jquery - CoffeeScript - 使用 JQuery 将点击事件绑定(bind)到动态加载的对象

javascript - Backbone 类模型不继承默认值

javascript - jQuery ajax : how to destroy submit if ajax validation fails?

python - 将 df 的 col 中的每个元素从字符串转换为列表

python - Python 中的 STRINGS 迭代(3)

javascript - 过滤树结构