Skip to content

Commit 1e59822

Browse files
committed
remove _null and _undefined
they have no significant effect on minified and gziped size. in fact they make things worse. file | before | after removal ---------------------------------------- concat | 325415 | 325297 min | 62070 | 62161 min + gzip | 25187 | 25176 The bottom line is that we are getting 0.05% decrease in size after gzip without all of the hassle of using underscores everywhere.
1 parent d95a692 commit 1e59822

22 files changed

Lines changed: 52 additions & 54 deletions

src/Angular.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ if ('i' !== 'I'.toLowerCase()) {
5252
function fromCharCode(code) { return String.fromCharCode(code); }
5353

5454

55-
var _undefined = undefined,
56-
_null = null,
57-
$$element = '$element',
55+
var $$element = '$element',
5856
$$update = '$update',
5957
$$scope = '$scope',
6058
$$validate = '$validate',
@@ -315,7 +313,7 @@ function isDefined(value){ return typeof value != $undefined; }
315313
* @param {*} value Reference to check.
316314
* @returns {boolean} True if `value` is an `Object` but not `null`.
317315
*/
318-
function isObject(value){ return value!=_null && typeof value == $object;}
316+
function isObject(value){ return value!=null && typeof value == $object;}
319317

320318

321319
/**

src/Browser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function Browser(window, document, body, XHR, $log) {
9595
var script = jqLite('<script>')
9696
.attr({type: 'text/javascript', src: url.replace('JSON_CALLBACK', callbackId)});
9797
window[callbackId] = function(data){
98-
window[callbackId] = _undefined;
98+
window[callbackId] = undefined;
9999
script.remove();
100100
completeOutstandingRequest(callback, 200, data);
101101
};
@@ -290,7 +290,7 @@ function Browser(window, document, body, XHR, $log) {
290290
var cookieLength, cookieArray, cookie, i, keyValue, index;
291291

292292
if (name) {
293-
if (value === _undefined) {
293+
if (value === undefined) {
294294
rawDocument.cookie = escape(name) + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
295295
} else {
296296
if (isString(value)) {

src/Compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ Compiler.prototype = {
330330
template.addChild(i, self.templatize(child, i, priority));
331331
});
332332
}
333-
return template.empty() ? _null : template;
333+
return template.empty() ? null : template;
334334
}
335335
};
336336

src/JSON.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var array = [].constructor;
1515
*/
1616
function toJson(obj, pretty) {
1717
var buf = [];
18-
toJsonArray(buf, obj, pretty ? "\n " : _null, []);
18+
toJsonArray(buf, obj, pretty ? "\n " : null, []);
1919
return buf.join('');
2020
}
2121

@@ -87,7 +87,7 @@ function toJsonArray(buf, obj, pretty, stack) {
8787
}
8888
stack.push(obj);
8989
}
90-
if (obj === _null) {
90+
if (obj === null) {
9191
buf.push($null);
9292
} else if (obj instanceof RegExp) {
9393
buf.push(angular['String']['quoteUnicode'](obj.toString()));
@@ -128,7 +128,7 @@ function toJsonArray(buf, obj, pretty, stack) {
128128
var childPretty = pretty ? pretty + " " : false;
129129
var keys = [];
130130
for(var k in obj) {
131-
if (obj[k] === _undefined)
131+
if (obj[k] === undefined)
132132
continue;
133133
keys.push(k);
134134
}

src/Resource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ ResourceFactory.prototype = {
128128
default:
129129
throw "Expected between 1-2 arguments [params, callback], got " + arguments.length + " arguments.";
130130
}
131-
var data = isPostOrPut ? this : _undefined;
131+
var data = isPostOrPut ? this : undefined;
132132
Resource[name].call(this, params, data, callback);
133133
};
134134
});

src/Scope.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function getter(instance, path, unboundFn) {
1515
if (isUndefined(instance) && key.charAt(0) == '$') {
1616
var type = angular['Global']['typeOf'](lastInstance);
1717
type = angular[type.charAt(0).toUpperCase()+type.substring(1)];
18-
var fn = type ? type[[key.substring(1)]] : _undefined;
18+
var fn = type ? type[[key.substring(1)]] : undefined;
1919
if (fn) {
2020
instance = bind(lastInstance, fn, lastInstance);
2121
return instance;

src/apis.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var angularGlobal = {
22
'typeOf':function(obj){
3-
if (obj === _null) return $null;
3+
if (obj === null) return $null;
44
var type = typeof obj;
55
if (type == $object) {
66
if (obj instanceof Array) return $array;

src/directives.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ angularDirective("ng:bind", function(expression, element){
202202
var lastValue = noop, lastError = noop;
203203
this.$onEval(function() {
204204
var error, value, html, isHtml, isDomElement,
205-
oldElement = this.hasOwnProperty($$element) ? this.$element : _undefined;
205+
oldElement = this.hasOwnProperty($$element) ? this.$element : undefined;
206206
this.$element = element;
207207
value = this.$tryEval(expression, function(e){
208208
error = formatError(e);
@@ -229,7 +229,7 @@ angularDirective("ng:bind", function(expression, element){
229229
element.html('');
230230
element.append(value);
231231
} else {
232-
element.text(value == _undefined ? '' : value);
232+
element.text(value == undefined ? '' : value);
233233
}
234234
}
235235
}, element);
@@ -257,7 +257,7 @@ function compileBindTemplate(template){
257257
});
258258
bindTemplateCache[template] = fn = function(element, prettyPrintJson){
259259
var parts = [], self = this,
260-
oldElement = this.hasOwnProperty($$element) ? self.$element : _undefined;
260+
oldElement = this.hasOwnProperty($$element) ? self.$element : undefined;
261261
self.$element = element;
262262
for ( var i = 0; i < bindings.length; i++) {
263263
var value = bindings[i].call(self, element);
@@ -767,7 +767,7 @@ angularDirective("ng:style", function(expression, element){
767767
this.$onEval(function(){
768768
var style = this.$eval(expression) || {}, key, mergedStyle = {};
769769
for(key in style) {
770-
if (resetStyle[key] === _undefined) resetStyle[key] = '';
770+
if (resetStyle[key] === undefined) resetStyle[key] = '';
771771
mergedStyle[key] = style[key];
772772
}
773773
for(key in resetStyle) {

src/formatters.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function formatter(format, parse) {return {'format':format, 'parse':parse || format};}
22
function toString(obj) {
3-
return (isDefined(obj) && obj !== _null) ? "" + obj : obj;
3+
return (isDefined(obj) && obj !== null) ? "" + obj : obj;
44
}
55

66
var NUMBER = /^\s*[-+]?\d*(\.\d*)?\s*$/;
@@ -94,8 +94,8 @@ angularFormatter['boolean'] = formatter(toString, toBoolean);
9494
</doc:example>
9595
*/
9696
angularFormatter.number = formatter(toString, function(obj){
97-
if (obj == _null || NUMBER.exec(obj)) {
98-
return obj===_null || obj === '' ? _null : 1*obj;
97+
if (obj == null || NUMBER.exec(obj)) {
98+
return obj===null || obj === '' ? null : 1*obj;
9999
} else {
100100
throw "Not a number";
101101
}

src/jqLite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function JQLiteData(element, key, value) {
105105
}
106106
cache[key] = value;
107107
} else {
108-
return cache ? cache[key] : _null;
108+
return cache ? cache[key] : null;
109109
}
110110
}
111111

0 commit comments

Comments
 (0)