LoginSignup
1
1

More than 5 years have passed since last update.

underscoreコードリーディング(without)

Posted at

underscoreに詳しくないので、勉強半分でソースコードを読む。

利用するバージョン

underscore.js(v1.8.3)

withoutとは

underscorejs.orgのwithout

こんな説明。

_.without(array, *values)

Returns a copy of the array with all instances of the values removed.


_.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
=> [2, 3, 4]


*valuesを除いたarrayのコピーを返す。

underscore.without

コード的にはこのあたり。

 // Return a version of the array that does not contain the specified value(s).
  _.without = function(array) {
    return _.difference(array, slice.call(arguments, 1));
  };

_.differenceを用いて配列の差分を出す。
_.differenceは2つ配列(引数)から、その差分の配列を返す関数。

array以外の引数はargumentsに格納されるので、それをsliceを用いて配列に直し、渡す。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1