I tried to use sugar. Previously I used it one year ago and it worked good in such way:
> npm install sugar
[email protected] D:\work\test\test
`-- [email protected]
> node
>> require('sugar');
{ [Function: Sugar]
.....
Array:
{ [Function: SugarChainable]
.....
compact: [Function: compact],
....
>> [1,null,2,undefined,3].compact()
TypeError: [1,null,2,undefined,3].compact is not a function
at repl:1:24
at ContextifyScript.Script.runInThisContext (vm.js:23:33)
at REPLServer.defaultEval (repl.js:339:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.onLine (repl.js:536:10)
at emitOne (events.js:101:20)
at REPLServer.emit (events.js:191:7)
at REPLServer.Interface._onLine (readline.js:241:10)
at REPLServer.Interface._line (readline.js:590:8)
Any ideas what is wrong now?
According to the SugarJS front page:
So you either need to use the chainable Sugar API:
This can be made into a one-liner like so:
Or extend natives:
While extending may seem simpler, there's a reason they've built it so you need to opt-in to this feature. Simply put, extending prototypes is dangerous as multiple libraries may want to extend the same prototypes and will cause collisions in their methods.