underscore函数

underscore提供如下函数,很是方便:

Underscore

提供了常用的函數。

  • Collections

    • each
    • map
    • reduce
    • reduceRight
    • find
    • filter
    • where
    • findWhere
    • reject
    • every
    • some
    • contains
    • invoke
    • pluck
    • max
    • min
    • sortBy
    • groupBy
    • countBy
    • shuffle
    • toArray
    • size
  • Arrays

    • first
    • initial
    • last
    • rest
    • compact
    • flatten
    • without
    • union
    • intersection
    • difference
    • uniq
    • zip
    • unzip
    • object
    • indexOf
    • lastIndexOf
    • sortedIndex
    • range
  • Functions

    • bind
    • bindAll
    • partial
    • memoize
    • delay
    • defer
    • throttle
    • debounce
    • once
    • after
    • wrap
    • compose
  • Objects

    • keys
    • values
    • pairs
    • invert
    • functions
    • extend
    • pick
    • omit
    • defaults
    • clone
    • tap
    • has
    • isEqual
    • isEmpty
    • isElement
    • isArray
    • isObject
    • isArguments
    • isFunction
    • isString
    • isNumber
    • isFinite
    • isBoolean
    • isDate
    • isRegExp
    • isNaN
    • isNull
    • isUnderfined
  • Utility

    • noConflict
    • identity
    • times
    • random
    • mixin
    • uniqueId
    • escape
    • unescape
    • result
    • template
  • Chaining

    • chain
    • value

Lo-Dash

建議使用Lo-Dash,性能優異很多的實現。

underscore.string

補充了underscore缺少的對字符串的操作,不過有些其實JavaScript原生就帶了。

  • capitalize
  • chop
  • clean
  • chars
  • swapCase
  • count
  • escapeHTML
  • unescapeHTML
  • insert
  • isBlank
  • join
  • lines
  • reverse
  • splice
  • startsWith
  • endsWith
  • succ
  • strip
  • lstrip
  • rstrip
  • titleize
  • camelize
  • classify
  • underscored
  • dasherize
  • humanize
  • trim
  • ltrim
  • rtrim
  • truncate
  • prune
  • words
  • sprintf
  • lpad
  • rpad
  • lrpad
  • center
  • ljust
  • rjust
  • toNumber
  • strRight
  • strRightBack
  • strLeft
  • strLeftBack
  • stripTags
  • toSentence
  • toSentenceSerial
  • repeat
  • surround
  • quote
  • unquote
  • slugify
  • naturalCmp
  • toBoolean

與Lo-Dash配合使用無壓力。

其他語言

Underscore被移植到了其他語言,例如Underscore.luaUnderscore.php

    原文作者:csmozy
    原文地址: https://segmentfault.com/a/1190000000367129
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞