prototype: use Object.isUndefined where possible.
This commit is contained in:
parent
b058e24a05
commit
07a16464e8
|
@ -1,3 +1,5 @@
|
|||
* For consistency: use Object.isUndefined where possible. [Tobie Langel]
|
||||
|
||||
* Make String#isJSON return false for empty or blank strings. Make Ajax.Response#responseJSON null when Ajax.Response#responseText is empty or blank. [Andrew Dupont, Thomas Fuchs, Tobie Langel]
|
||||
|
||||
* Make Ajax.Response#_getResponseJSON use Ajax.Response#responseText. [Tobie Langel]
|
||||
|
|
|
@ -242,7 +242,7 @@ Ajax.Response = Class.create({
|
|||
|
||||
if(readyState == 4) {
|
||||
var xml = transport.responseXML;
|
||||
this.responseXML = xml === undefined ? null : xml;
|
||||
this.responseXML = Object.isUndefined(xml) ? null : xml;
|
||||
this.responseJSON = this._getResponseJSON();
|
||||
}
|
||||
},
|
||||
|
|
|
@ -100,7 +100,7 @@ Object.extend(Array.prototype, {
|
|||
var results = [];
|
||||
this.each(function(object) {
|
||||
var value = Object.toJSON(object);
|
||||
if (value !== undefined) results.push(value);
|
||||
if (!Object.isUndefined(value)) results.push(value);
|
||||
});
|
||||
return '[' + results.join(', ') + ']';
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ Object.extend = function(destination, source) {
|
|||
Object.extend(Object, {
|
||||
inspect: function(object) {
|
||||
try {
|
||||
if (object === undefined) return 'undefined';
|
||||
if (Object.isUndefined(object)) return 'undefined';
|
||||
if (object === null) return 'null';
|
||||
return object.inspect ? object.inspect() : object.toString();
|
||||
} catch (e) {
|
||||
|
@ -94,7 +94,7 @@ Object.extend(Object, {
|
|||
var results = [];
|
||||
for (var property in object) {
|
||||
var value = Object.toJSON(object[property]);
|
||||
if (value !== undefined)
|
||||
if (!Object.isUndefined(value))
|
||||
results.push(property.toJSON() + ': ' + value);
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ Object.extend(Function.prototype, {
|
|||
},
|
||||
|
||||
bind: function() {
|
||||
if (arguments.length < 2 && arguments[0] === undefined) return this;
|
||||
if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
|
||||
var __method = this, args = $A(arguments), object = args.shift();
|
||||
return function() {
|
||||
return __method.apply(object, args.concat($A(arguments)));
|
||||
|
|
|
@ -286,7 +286,7 @@ Element.Methods = {
|
|||
var attributes = { }, t = Element._attributeTranslations.write;
|
||||
|
||||
if (typeof name == 'object') attributes = name;
|
||||
else attributes[name] = value === undefined ? true : value;
|
||||
else attributes[name] = Object.isUndefined(value) ? true : value;
|
||||
|
||||
for (var attr in attributes) {
|
||||
var name = t.names[attr] || attr, value = attributes[attr];
|
||||
|
@ -412,7 +412,7 @@ Element.Methods = {
|
|||
if (property == 'opacity') element.setOpacity(styles[property]);
|
||||
else
|
||||
elementStyle[(property == 'float' || property == 'cssFloat') ?
|
||||
(elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') :
|
||||
(Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
|
||||
property] = styles[property];
|
||||
|
||||
return element;
|
||||
|
|
|
@ -102,7 +102,7 @@ var Enumerable = {
|
|||
},
|
||||
|
||||
inGroupsOf: function(number, fillWith) {
|
||||
fillWith = fillWith === undefined ? null : fillWith;
|
||||
fillWith = Object.isUndefined(fillWith) ? null : fillWith;
|
||||
return this.eachSlice(number, function(slice) {
|
||||
while(slice.length < number) slice.push(fillWith);
|
||||
return slice;
|
||||
|
@ -129,7 +129,7 @@ var Enumerable = {
|
|||
var result;
|
||||
this.each(function(value, index) {
|
||||
value = iterator(value, index);
|
||||
if (result == undefined || value >= result)
|
||||
if (result == null || value >= result)
|
||||
result = value;
|
||||
});
|
||||
return result;
|
||||
|
@ -140,7 +140,7 @@ var Enumerable = {
|
|||
var result;
|
||||
this.each(function(value, index) {
|
||||
value = iterator(value, index);
|
||||
if (result == undefined || value < result)
|
||||
if (result == null || value < result)
|
||||
result = value;
|
||||
});
|
||||
return result;
|
||||
|
|
|
@ -6,7 +6,7 @@ var Form = {
|
|||
|
||||
serializeElements: function(elements, options) {
|
||||
if (typeof options != 'object') options = { hash: !!options };
|
||||
else if (options.hash === undefined) options.hash = true;
|
||||
else if (Object.isUndefined(options.hash)) options.hash = true;
|
||||
var key, value, submitted = false, submit = options.submit;
|
||||
|
||||
var data = elements.inject({ }, function(result, element) {
|
||||
|
@ -204,17 +204,17 @@ Form.Element.Serializers = {
|
|||
},
|
||||
|
||||
inputSelector: function(element, value) {
|
||||
if (value === undefined) return element.checked ? element.value : null;
|
||||
if (Object.isUndefined(value)) return element.checked ? element.value : null;
|
||||
else element.checked = !!value;
|
||||
},
|
||||
|
||||
textarea: function(element, value) {
|
||||
if (value === undefined) return element.value;
|
||||
if (Object.isUndefined(value)) return element.value;
|
||||
else element.value = value;
|
||||
},
|
||||
|
||||
select: function(element, index) {
|
||||
if (index === undefined)
|
||||
if (Object.isUndefined(index))
|
||||
return this[element.type == 'select-one' ?
|
||||
'selectOne' : 'selectMany'](element);
|
||||
else {
|
||||
|
|
|
@ -31,7 +31,7 @@ Object.extend(String.prototype, {
|
|||
|
||||
sub: function(pattern, replacement, count) {
|
||||
replacement = this.gsub.prepareReplacement(replacement);
|
||||
count = count === undefined ? 1 : count;
|
||||
count = Object.isUndefined(count) ? 1 : count;
|
||||
|
||||
return this.gsub(pattern, function(match) {
|
||||
if (--count < 0) return match[0];
|
||||
|
@ -46,7 +46,7 @@ Object.extend(String.prototype, {
|
|||
|
||||
truncate: function(length, truncation) {
|
||||
length = length || 30;
|
||||
truncation = truncation === undefined ? '...' : truncation;
|
||||
truncation = Object.isUndefined(truncation) ? '...' : truncation;
|
||||
return this.length > length ?
|
||||
this.slice(0, length - truncation.length) + truncation : String(this);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue