用于骨干比较器的最小javascript字符串值

Minimum javascript string value for use in backbone comparator

本文关键字:javascript 字符串 比较器 用于      更新时间:2023-09-26

我想要在比较器中使用一个最小字符串值。假设我的验证防止name为空字符串。

这看起来工作正常。是否有任何"name"值会导致失败?

S.FileList = Backbone.Collection.extend
  model: S.File                    
  comparator: (file) ->     
    # We add display files alphabetically, but with meta.file at the top. 
    if file.get("name") == "meta.file"
      return ""
    return file.get("name")

假设您的验证阻止name为空字符串,并强制它为字符串:是的,这将工作。"" < str,其中str""以外的任意字符串。

你要确保typeof name is 'string',因为while

"" < "0"

是真的,

"" < 0

是假的。