Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
['rocksteady','and','bebop'].first(1); > ["rocksteady"]
['rocksteady','and','bebop'].from(1); > ["and","bebop"]
['rocksteady','and','bebop'].slice(0, 1); > ["rocksteady"]
['rocksteady','and','bebop'].slice(1); > ["and","bebop"]
В Sugar есть основные методы, такие как bind, который позволяет определить область видимости функции.
[1,2].add([2,3]); -> [1,2].push(2,3); или [1,2].concat(3,4)
'off with her head!'.each(/he.+?\b/g); -> 'off with her head!'.match(/he.+?\b/g);
'off with her head!'.startsWith(/[a-z]ff/); -> /^[a-z]ff/.test('off with her head!');
'off with her head!'.first(3); -> 'off with her head!'.substr(0, 3);
'off with her head!'.from(3); -> 'off with her head!'.substr(3);
(125.425).round(2); -> (125.425).toFixed(2);
Date.create('June 15, 2002'); -> new Date('June 15, 2002');
Date.create('2002/06/15'); -> new Date('2002/06/15');
Date.create('15 June, 2002'); -> new Date('15 June, 2002');
Date.create(888888888899); -> new Date(888888888899);
['a','b','c'].indexOf('c');
Object.keys({ broken: 'wear' });
(function(a) {
/* this = 'wasabi', a = 'bobby' */
}).bind('wasabi', 'bobby')();
Date.create('2002-06-15'); -> new Date('2002-06-15');
Date.create().iso(); -> (new Date).toISOString()
Sugar modifies native objects, and is more concerned with intuitive syntax, whereas Underscore.js leaves native objects alone, and is more oriented toward performance.
[{ foo:'bar' }, { moo:'car' }].indexOf({ moo: 'car' });
Sugar — подслащённый Javascript