underscore.string icon indicating copy to clipboard operation
underscore.string copied to clipboard

splice conflict

Open pgherveou opened this issue 13 years ago • 7 comments

Hello there

I just noticed the following problem

/*  without underscore.string */
_([1, 2, 3]).splice(0, 1) // returns [2, 3]

/*  with underscore.string */
_([1, 2, 3]).splice(0, 1) // returns ",2,3"

could the splice method be renamed so it does not conflict with Array.splice ?

pgherveou avatar Oct 09 '12 21:10 pgherveou

This is really bad. Will probably fix this later today.

Thanks for the heads up.

rwz avatar Oct 10 '12 10:10 rwz

Actually, I've just checked. Underscore.string still works fine and doesn't break any of native underscore tests. Also, Underscore does not even have splice method.

So, check your Underscore version, it might be outdated.

rwz avatar Oct 16 '12 11:10 rwz

I think it can be a problem, because in that case _([1, 2, 3]).splice(0, 1) Underscore delegates splice, reverse and other native functions to the array. http://underscorejs.org/#chaining For ex _([1,2,3]).join('') // => '123'

edtsech avatar Oct 16 '12 11:10 edtsech

@edtsech oh, this might be the case. Will investigate today.

rwz avatar Oct 16 '12 11:10 rwz

@pgherveou how do you attach underscore.string? I couldn't reproduce this issue in the lastest versions of underscore and underscore.string.

_([1, 2, 3]).splice(0, 1) # => [2, 3]

rwz avatar Oct 16 '12 12:10 rwz

Using node this what i get

> npm ls | grep underscore
├── [email protected]
├── [email protected]
_ = require('underscore');
_.mixin(require('underscore.string').exports());
console.log(_([1, 2, 3]).splice(0, 1));
> ,2,3

pgherveou avatar Oct 16 '12 12:10 pgherveou

@pgherveou ah, ok, I got it. There is not easy way to fix that right now. I might recommend you try to using underscore.string separately as it described in README.

rwz avatar Oct 16 '12 12:10 rwz