diff --git a/lib/array.js b/lib/array.js index 315f6489d..54160af70 100644 --- a/lib/array.js +++ b/lib/array.js @@ -398,7 +398,7 @@ array[AlphanumericSortEquivalents] = equivalents; } - extend(array, false, false, { + extend(array, false, true, { /*** * @@ -468,7 +468,11 @@ checkCallback(f); index = arrayFind(this, f, 0, false, true, context); return isUndefined(index) ? -1 : index; - }, + } + + }); + + extend(array, true, true, { /*** * @method findAll(, [index] = 0, [loop] = false) @@ -1158,8 +1162,10 @@ }); + // Aliases - extend(array, true, false, { + + extend(array, true, true, { /*** * @method all() @@ -1228,7 +1234,7 @@ ***/ function buildEnumerableMethods(names, mapping) { - extendSimilar(object, false, false, names, function(methods, name) { + extendSimilar(object, false, true, names, function(methods, name) { methods[name] = function(obj, arg1, arg2) { var result, coerced = keysWithObjectCoercion(obj), matcher; if(!mapping) { @@ -1256,11 +1262,11 @@ buildObjectInstanceMethods(names, Hash); } - function exportSortAlgorithms() { + function exportSortAlgorithm() { array[AlphanumericSort] = collateStrings; } - extend(object, false, false, { + extend(object, false, true, { 'map': function(obj, map) { var result = {}, key, value; @@ -1311,5 +1317,5 @@ buildEnumerableMethods(EnumerableFindingMethods); buildEnumerableMethods(EnumerableMappingMethods, true); buildObjectInstanceMethods(EnumerableOtherMethods, Hash); - exportSortAlgorithms(); + exportSortAlgorithm(); diff --git a/lib/core.js b/lib/core.js index af993ca43..a087717a1 100644 --- a/lib/core.js +++ b/lib/core.js @@ -99,7 +99,7 @@ function initializeClass(klass) { if(klass['SugarMethods']) return; defineProperty(klass, 'SugarMethods', {}); - extend(klass, false, false, { + extend(klass, false, true, { 'extend': function(methods, override, instance) { extend(klass, instance !== false, override, methods); }, diff --git a/lib/date.js b/lib/date.js index 868892b8c..beb6715b8 100644 --- a/lib/date.js +++ b/lib/date.js @@ -1387,7 +1387,7 @@ ***/ function buildDateMethods() { - extendSimilar(date, true, false, DateUnits, function(methods, u, i) { + extendSimilar(date, true, true, DateUnits, function(methods, u, i) { var name = u.name, caps = simpleCapitalize(name), multiplier = u.multiplier(), since, until; u.addMethod = 'add' + caps + 's'; // "since/until now" only count "past" an integer, i.e. "2 days ago" is @@ -1527,7 +1527,7 @@ } function buildFormatShortcuts() { - extendSimilar(date, true, false, 'short,long,full', function(methods, name) { + extendSimilar(date, true, true, 'short,long,full', function(methods, name) { methods[name] = function(localeCode) { return formatDate(this, name, false, localeCode); } @@ -1599,7 +1599,7 @@ var special = 'today,yesterday,tomorrow,weekday,weekend,future,past'.split(','); var weekdays = English['weekdays'].slice(0,7); var months = English['months'].slice(0,12); - extendSimilar(date, true, false, special.concat(weekdays).concat(months), function(methods, name) { + extendSimilar(date, true, true, special.concat(weekdays).concat(months), function(methods, name) { methods['is'+ simpleCapitalize(name)] = function(utc) { return this.is(name, 0, utc); }; @@ -1627,16 +1627,16 @@ } function setDateProperties() { - date.extend({ + extend(date, false , true, { 'RFC1123': '{Dow}, {dd} {Mon} {yyyy} {HH}:{mm}:{ss} {tz}', 'RFC1036': '{Weekday}, {dd}-{Mon}-{yy} {HH}:{mm}:{ss} {tz}', 'ISO8601_DATE': '{yyyy}-{MM}-{dd}', 'ISO8601_DATETIME': '{yyyy}-{MM}-{dd}T{HH}:{mm}:{ss}.{fff}{isotz}' - }, false, false); + }); } - date.extend({ + extend(date, false, true, { /*** * @method Date.create(, [locale] = currentLocale) @@ -1751,9 +1751,9 @@ addDateInputFormat(getLocalization(localeCode), format, match); } - }, false, false); + }); - date.extend({ + extend(date, true, true, { /*** * @method set(, [reset] = false) @@ -2162,7 +2162,7 @@ // Instance aliases - date.extend({ + extend(date, true, true, { /*** * @method iso() @@ -2363,7 +2363,7 @@ number.extend(methods); } - number.extend({ + extend(number, true, true, { /*** * @method duration([locale] = currentLocale) diff --git a/lib/function.js b/lib/function.js index b38be8867..aaee21458 100644 --- a/lib/function.js +++ b/lib/function.js @@ -24,7 +24,7 @@ }, ms)); } - extend(Function, true, false, { + extend(Function, true, true, { /*** * @method lazy([ms] = 1, [immediate] = false, [limit] = Infinity) diff --git a/lib/inflections.js b/lib/inflections.js index 233a28bf4..b60675cfe 100644 --- a/lib/inflections.js +++ b/lib/inflections.js @@ -298,7 +298,7 @@ Inflector.uncountable('equipment,information,rice,money,species,series,fish,sheep,jeans'.split(',')); - extend(string, true, false, { + extend(string, true, true, { /*** * @method pluralize() diff --git a/lib/language.js b/lib/language.js index 89fa34643..26b10db3c 100644 --- a/lib/language.js +++ b/lib/language.js @@ -278,7 +278,7 @@ 'vy': 'ꝡ' }; - extend(string, true, false, { + extend(string, true, true, { /*** * @method normalize() * @returns String diff --git a/lib/number.js b/lib/number.js index 7ae62e5ce..6a016c74d 100644 --- a/lib/number.js +++ b/lib/number.js @@ -30,7 +30,7 @@ } - extend(number, false, false, { + extend(number, false, true, { /*** * @method Number.random([n1], [n2]) @@ -54,7 +54,7 @@ }); - extend(number, true, false, { + extend(number, true, true, { /*** * @method log( = Math.E) @@ -383,12 +383,12 @@ return precision ? withPrecision(this, precision, fn) : fn(this); } } - extend(number, true, false, { + extend(number, true, true, { 'ceil': createRoundingFunction(ceil), 'round': createRoundingFunction(round), 'floor': createRoundingFunction(floor) }); - extendSimilar(number, true, false, 'abs,pow,sin,asin,cos,acos,tan,atan,exp,pow,sqrt', function(methods, name) { + extendSimilar(number, true, true, 'abs,pow,sin,asin,cos,acos,tan,atan,exp,pow,sqrt', function(methods, name) { methods[name] = function(a, b) { return math[name](this, a, b); } diff --git a/lib/object.js b/lib/object.js index c8b14375b..e0d4b0bb2 100644 --- a/lib/object.js +++ b/lib/object.js @@ -118,7 +118,7 @@ * ***/ function buildTypeMethods() { - extendSimilar(object, false, false, ClassNames, function(methods, name) { + extendSimilar(object, false, true, ClassNames, function(methods, name) { var method = 'is' + name; ObjectTypeMethods.push(method); methods[method] = typeChecks[name]; @@ -195,7 +195,7 @@ }); - extend(object, false, false, { + extend(object, false, true, { 'isObject': function(obj) { return isPlainObject(obj); diff --git a/lib/range.js b/lib/range.js index d7aeb581f..81d1f3457 100644 --- a/lib/range.js +++ b/lib/range.js @@ -87,7 +87,7 @@ return this.isValid() ? this.start + ".." + this.end : 'Invalid Range'; }; - extend(Range, true, false, { + extend(Range, true, true, { /*** * @method isValid() @@ -261,7 +261,7 @@ }); - extend(Range, true, false, { + extend(Range, true, true, { /*** * @method step() @@ -294,7 +294,7 @@ * @extra If either [start] or [end] are null, they will default to the current date. ***/ [number, string, date].forEach(function(klass) { - extend(klass, false, false, { + extend(klass, false, true, { 'range': function(start, end) { if(klass.create) { @@ -313,7 +313,7 @@ * ***/ - extend(number, true, false, { + extend(number, true, true, { /*** * @method upto(, [fn], [step] = 1) @@ -357,7 +357,7 @@ }); - extend(number, true, false, { + extend(number, true, true, { /*** * @method downto(, [fn], [step] = 1) diff --git a/lib/regexp.js b/lib/regexp.js index f3ce60253..51ada04ed 100644 --- a/lib/regexp.js +++ b/lib/regexp.js @@ -12,7 +12,7 @@ * ***/ - extend(regexp, false, false, { + extend(regexp, false, true, { /*** * @method RegExp.escape( = '') @@ -31,7 +31,7 @@ }); - extend(regexp, true, false, { + extend(regexp, true, true, { /*** * @method getFlags() diff --git a/lib/string.js b/lib/string.js index 6715e364b..d655b84bc 100644 --- a/lib/string.js +++ b/lib/string.js @@ -187,7 +187,7 @@ }); - extend(string, true, false, { + extend(string, true, true, { /*** * @method escapeRegExp() @@ -889,7 +889,7 @@ // Aliases - extend(string, true, false, { + extend(string, true, true, { /*** * @method insert() diff --git a/test/default.html b/test/default.html index 717121c12..4aee88951 100644 --- a/test/default.html +++ b/test/default.html @@ -1,12 +1,13 @@ - Sugar Full Package + Sugar Default Package + diff --git a/test/full.html b/test/full.html index 9fe1e47f3..d435cadd7 100644 --- a/test/full.html +++ b/test/full.html @@ -7,6 +7,7 @@ + diff --git a/test/javascripts/overrides.js b/test/javascripts/overrides.js new file mode 100644 index 000000000..d77df4a32 --- /dev/null +++ b/test/javascripts/overrides.js @@ -0,0 +1,59 @@ + +var overridingFunction = function() { + return 'Something totally unexpected!'; +} + +Object.map = overridingFunction; +Object.each = overridingFunction; +Object.any = overridingFunction; +Object.sum = overridingFunction; +Object.isObject = overridingFunction; +Object.isNumber = overridingFunction; +Object.extend = overridingFunction; + +Array.create = overridingFunction; +Array.prototype.findAll = overridingFunction; +Array.prototype.all = overridingFunction; +Array.prototype.add = overridingFunction; +Array.prototype.groupBy = overridingFunction; + +String.extend = overridingFunction; +String.range = overridingFunction; +String.prototype.each = overridingFunction; +String.prototype.to = overridingFunction; +String.prototype.pad = overridingFunction; +String.prototype.insert = overridingFunction; +String.prototype.pluralize = overridingFunction; +String.prototype.hankaku = overridingFunction; + +Number.random = overridingFunction; +Number.range = overridingFunction; +Number.prototype.log = overridingFunction; +Number.prototype.ceil = overridingFunction; +Number.prototype.round = overridingFunction; +Number.prototype.floor = overridingFunction; +Number.prototype.abs = overridingFunction; +Number.prototype.upto = overridingFunction; +Number.prototype.downto = overridingFunction; +Number.prototype.secondsBefore = overridingFunction; +Number.prototype.duration = overridingFunction; + +RegExp.escape = overridingFunction; +RegExp.prototype.getFlags = overridingFunction; +RegExp.prototype.setFlags = overridingFunction; + +Function.prototype.lazy = overridingFunction; +Function.prototype.throttle = overridingFunction; +Function.prototype.debounce = overridingFunction; + + +Date['ISO8601_DATE'] = 'none!'; +Date.create = overridingFunction; +Date.range = overridingFunction; +Date.prototype.set = overridingFunction; +Date.prototype.iso = overridingFunction; +Date.prototype.endOfDay = overridingFunction; +Date.prototype.long = overridingFunction; +Date.prototype.isToday = overridingFunction; +Date.prototype.addMinutes = overridingFunction; +