Permalink
Browse files

switch use of hasOwnProperty to checking typeof, not necessarily need…

…ing to know if it's a direct or inherited property
  • Loading branch information...
zepheiryan committed Dec 10, 2011
1 parent 7e3c5b6 commit 65f0af05795ff6f05e7ee05a1626847d113f1cb2
@@ -55,7 +55,7 @@ Exhibit.Collection.create = function(id, configuration, database) {
var collection = new Exhibit.Collection(id, database);
collection._setElement();
- if (configuration.hasOwnProperty("itemTypes")) {
+ if (typeof configuration["itemTypes"] !== "undefined") {
collection._itemTypes = configuration.itemTypes;
collection._update = Exhibit.Collection._typeBasedCollection_update;
} else {
@@ -108,16 +108,16 @@ Exhibit.Collection.create2 = function(id, configuration, uiContext) {
database = uiContext.getDatabase();
- if (configuration.hasOwnProperty("expression")) {
+ if (typeof configuration["expression"] !== "undefined") {
collection = new Exhibit.Collection(id, database);
collection._setElement();
collection._expression = Exhibit.ExpressionParser.parse(configuration.expression);
- collection._baseCollection = (configuration.hasOwnProperty("baseCollectionID")) ?
+ collection._baseCollection = (typeof configuration["baseCollectionID"] !== "undefined") ?
uiContext.getExhibit().getCollection(configuration.baseCollectionID) :
uiContext.getCollection();
- collection._restrictBaseCollection = (configuration.hasOwnProperty("restrictBaseCollection")) ?
+ collection._restrictBaseCollection = (typeof configuration["restrictBaseCollection"] !== "undefined") ?
configuration.restrictBaseCollection : false;
if (collection._restrictBaseCollection) {
@@ -392,7 +392,7 @@ Exhibit.Collection.prototype.equals = function(collection) {
* Handle removing the collection from the local context.
*/
Exhibit.Collection.prototype.dispose = function() {
- if (this.hasOwnProperty("_baseCollection")) {
+ if (typeof this["_baseCollection"] !== "undefined") {
this._baseCollection = null;
this._expression = null;
}
@@ -93,13 +93,13 @@ Exhibit.Database._LocalImpl.prototype.loadData = function(o, baseURI) {
if (typeof baseURI === "undefined") {
baseURI = location.href;
}
- if (o.hasOwnProperty("types")) {
+ if (typeof o["types"] !== "undefined") {
this.loadTypes(o.types, baseURI);
}
- if (o.hasOwnProperty("properties")) {
+ if (typeof o["properties"] !== "undefined") {
this.loadProperties(o.properties, baseURI);
}
- if (o.hasOwnProperty("items")) {
+ if (typeof o["items"] !== "undefined") {
this.loadItems(o.items, baseURI);
}
};
@@ -126,7 +126,7 @@ Exhibit.Database._LocalImpl.prototype.loadTypes = function(typeEntries, baseURI)
if (typeof typeID === "string") {
typeEntry = typeEntries[typeID];
if (typeof typeEntry === "object") {
- if (this._types.hasOwnProperty(typeID)) {
+ if (typeof this._types[typeID] !== "undefined") {
type = this._types[typeID];
} else {
type = new Exhibit.Database.Type(typeID);
@@ -139,11 +139,11 @@ Exhibit.Database._LocalImpl.prototype.loadTypes = function(typeEntries, baseURI)
}
}
- if (!type._custom.hasOwnProperty("uri")) {
+ if (typeof type._custom["uri"] === "undefined") {
type._custom["uri"] = baseURI + "type#" + encodeURIComponent(typeID);
}
- if (!type._custom.hasOwnProperty("label")) {
+ if (typeof type._custom["label"] === "undefined") {
type._custom["label"] = typeID;
}
}
@@ -180,46 +180,46 @@ Exhibit.Database._LocalImpl.prototype.loadProperties = function(propertyEntries,
if (typeof propertyID === "string") {
propertyEntry = propertyEntries[propertyID];
if (typeof propertyEntry === "object") {
- if (this._properties.hasOwnProperty(propertyID)) {
+ if (typeof this._properties[propertyID] !== "undefined") {
property = this._properties[propertyID];
} else {
property = new Exhibit.Database.Property(propertyID, this);
this._properties[propertyID] = property;
}
- property._uri = propertyEntry.hasOwnProperty("uri") ?
+ property._uri = typeof propertyEntry["uri"] !== "undefined" ?
propertyEntry.uri :
(baseURI + "property#" + encodeURIComponent(propertyID));
- property._valueType = propertyEntry.hasOwnProperty("valueType") ?
+ property._valueType = typeof propertyEntry["valueType"] !== "undefined" ?
propertyEntry.valueType :
"text";
- property._label = propertyEntry.hasOwnProperty("label") ?
+ property._label = typeof propertyEntry["label"] !== "undefined" ?
propertyEntry.label :
propertyID;
- property._pluralLabel = propertyEntry.hasOwnProperty("pluralLabel") ?
+ property._pluralLabel = typeof propertyEntry["pluralLabel"] !== "undefined" ?
propertyEntry.pluralLabel :
property._label;
- property._reverseLabel = propertyEntry.hasOwnProperty("reverseLabel") ?
+ property._reverseLabel = typeof propertyEntry["reverseLabel"] !== "undefined" ?
propertyEntry.reverseLabel :
("!" + property._label);
- property._reversePluralLabel = propertyEntry.hasOwnProperty("reversePluralLabel") ?
+ property._reversePluralLabel = typeof propertyEntry["reversePluralLabel"] !== "undefined" ?
propertyEntry.reversePluralLabel :
("!" + property._pluralLabel);
- property._groupingLabel = propertyEntry.hasOwnProperty("groupingLabel") ?
+ property._groupingLabel = typeof propertyEntry["groupingLabel"] !== "undefined" ?
propertyEntry.groupingLabel :
property._label;
- property._reverseGroupingLabel = propertyEntry.hasOwnProperty("reverseGroupingLabel") ?
+ property._reverseGroupingLabel = typeof propertyEntry["reverseGroupingLabel"] !== "undefined" ?
propertyEntry.reverseGroupingLabel :
property._reverseLabel;
- if (propertyEntry.hasOwnProperty("origin")) {
+ if (typeof propertyEntry["origin"] !== "undefined") {
property._origin = propertyEntry.origin;
}
}
@@ -283,7 +283,7 @@ Exhibit.Database._LocalImpl.prototype.loadItems = function(itemEntries, baseURI)
* @returns {Exhibit.Database.Type} The corresponding database type.
*/
Exhibit.Database._LocalImpl.prototype.getType = function(typeID) {
- return this._types.hasOwnProperty(typeID) ?
+ return typeof this._types[typeID] ?
this._types[typeID] :
null;
};
@@ -296,7 +296,7 @@ Exhibit.Database._LocalImpl.prototype.getType = function(typeID) {
* @returns {Exhibit.Database._Property} The corresponding database property.
*/
Exhibit.Database._LocalImpl.prototype.getProperty = function(propertyID) {
- return this._properties.hasOwnProperty(propertyID) ?
+ return typeof this._properties[propertyID] !== "undefined" ?
this._properties[propertyID] :
null;
};
@@ -764,28 +764,28 @@ Exhibit.Database._LocalImpl.prototype._loadLinks = function(links, database, fDo
Exhibit.Database._LocalImpl.prototype._loadItem = function(itemEntry, indexFunction, baseURI) {
var id, label, uri, type, isArray, p, v, j;
- if (!itemEntry.hasOwnProperty("label") &&
- !itemEntry.hasOwnProperty("id")) {
+ if (typeof itemEntry["label"] === "undefined" &&
+ typeof itemEntry["id"] === "undefined") {
Exhibit.Debug.warn("Item entry has no label and no id: " +
JSON.toJSONString(itemEntry));
itemEntry.label = "item" + Math.ceil(Math.random()*1000000);
}
- if (!itemEntry.hasOwnProperty("label")) {
+ if (typeof itemEntry["label"] === "undefined") {
id = itemEntry.id;
if (!this._items.contains(id)) {
Exhibit.Debug.warn("Cannot add new item containing no label: " +
JSON.toJSONString(itemEntry));
}
} else {
label = itemEntry.label;
- id = itemEntry.hasOwnProperty("id") ?
+ id = typeof itemEntry["id"] !== "undefined" ?
itemEntry.id :
label;
- uri = itemEntry.hasOwnProperty("uri") ?
+ uri = typeof itemEntry["uri"] !== "undefined" ?
itemEntry.uri :
(baseURI + "item#" + encodeURIComponent(id));
- type = itemEntry.hasOwnProperty("type") ?
+ type = typeof itemEntry["type"] !== "undefined" ?
itemEntry.type :
"Item";
@@ -851,7 +851,7 @@ Exhibit.Database._LocalImpl.prototype._loadItem = function(itemEntry, indexFunct
*/
Exhibit.Database._LocalImpl.prototype._ensureTypeExists = function(typeID, baseURI) {
var type;
- if (!this._types.hasOwnProperty(typeID)) {
+ if (typeof this._types[typeID] === "undefined") {
type = new Exhibit.Database.Type(typeID);
type._custom["uri"] = baseURI + "type#" + encodeURIComponent(typeID);
@@ -871,7 +871,7 @@ Exhibit.Database._LocalImpl.prototype._ensureTypeExists = function(typeID, baseU
*/
Exhibit.Database._LocalImpl.prototype._ensurePropertyExists = function(propertyID, baseURI) {
var property;
- if (!this._properties.hasOwnProperty(propertyID)) {
+ if (typeof this._properties[propertyID] === "undefined") {
property = new Exhibit.Database.Property(propertyID, this);
property._uri = baseURI + "property#" + encodeURIComponent(propertyID);
@@ -45,13 +45,13 @@ Exhibit.Exporter.BibTex.wrapOne = function(s, first, last) {
Exhibit.Exporter.BibTex.exportOne = function(itemID, o) {
var type, key, prop, s = "";
- if (o.hasOwnProperty("pub-type")) {
+ if (typeof o["pub-type"] !== "undefined") {
type = o["pub-type"];
- } else if (o.hasOwnProperty("type")) {
+ } else if (typeof o["type"] !== "undefined") {
type = o["type"];
}
- if (o.hasOwnProperty("key")) {
+ if (typeof o["key"] !== "undefined") {
key = o["key"];
} else {
key = itemID;
@@ -63,7 +63,7 @@ Exhibit.Exporter.BibTex.exportOne = function(itemID, o) {
for (prop in o) {
if (o.hasOwnProperty(prop)) {
- if (!Exhibit.Exporter.BibTex._excludeProperties.hasOwnProperty(prop)) {
+ if (typeof Exhibit.Exporter.BibTex._excludeProperties[prop] === "undefined") {
s += "\t" + (prop === "label" ?
"title" :
prop) + " = \"";
@@ -56,9 +56,9 @@ Exhibit.Exporter.RDFXML.exportOne = function(itemID, o, properties, propertyIDTo
s += "<rdf:Description rdf:about=\"" + uri + "\">\n";
for (propertyID in o) {
- if (o.hasOwnProperty(propertyID) && properties.hasOwnProperty(propertyID)) {
+ if (o.hasOwnProperty(propertyID) && typeof properties[propertyID] !== "undefined") {
valueType = properties[propertyID].valueType;
- if (propertyIDToQualifiedName.hasOwnProperty(propertyID)) {
+ if (typeof propertyIDToQualifiedName[propertyID] !== "undefined") {
qname = propertyIDToQualifiedName[propertyID];
propertyString = qname.prefix + ":" + qname.localName;
} else {
@@ -41,7 +41,7 @@ Exhibit.Exporter.SemanticWikiText.exportOne = function(itemID, o, properties) {
s += uri + "\n";
for (prop in o) {
- if (o.hasOwnProperty(prop) && properties.hasOwnProperty(prop)) {
+ if (o.hasOwnProperty(prop) && typeof properties[prop] !== "undefined") {
valueType = properties[prop].valueType;
values = o[prop];
if (valueType === "item") {
@@ -98,7 +98,7 @@ Exhibit.ExpressionParser._internalParse = function(scanner, several) {
identifier = token.value;
next();
- if (Exhibit.Controls.hasOwnProperty(identifier)) {
+ if (typeof Exhibit.Controls[identifier] !== "undefined") {
if (token !== null && token.type === Scanner.DELIMITER && token.value === "(") {
next();
@@ -35,7 +35,7 @@ Exhibit.Expression._FunctionCall.prototype.evaluate = function(
args.push(this._args[i].evaluate(roots, rootValueTypes, defaultRootName, database));
}
- if (Exhibit.Functions.hasOwnProperty(this._name)) {
+ if (typeof Exhibit.Functions[this._name] !== "undefined") {
return Exhibit.Functions[this._name].f(args);
} else {
throw new Error("No such function named " + this._name);
@@ -205,7 +205,7 @@ Exhibit.Functions["date-range"] = {
_computeRange: function(from, to, interval) {
var range = to - from;
if (isFinite(range)) {
- if (Exhibit.DateTime.hasOwnProperty(interval.toUpperCase())) {
+ if (typeof Exhibit.DateTime[interval.toUpperCase()] !== "undefined") {
range = Math.round(range / Exhibit.DateTime.gregorianUnitLengths[Exhibit.DateTime[interval.toUpperCase()]]);
}
return range;
@@ -246,7 +246,7 @@ Exhibit.Functions["distance"] = {
roundTo = 1;
}
if (isFinite(range)) {
- if (this._units.hasOwnProperty(unit)) {
+ if (typeof this._units[unit] !== "undefined") {
range = range / this._units[unit];
}
return Exhibit.Util.round(range, roundTo);
@@ -95,12 +95,12 @@ Exhibit.Expression.Path.prototype.evaluate = function(
rootName = (typeof this._rootName !== "undefined" && this._rootName !== null) ?
this._rootName :
defaultRootName;
- valueType = rootValueTypes.hasOwnProperty(rootName) ?
+ valueType = typeof rootValueTypes[rootName] !== "undefined" ?
rootValueTypes[rootName] :
"text";
collection = null;
- if (roots.hasOwnProperty(rootName)) {
+ if (typeof roots[rootName] !== "undefined") {
root = roots[rootName];
if (root instanceof Exhibit.Set || root instanceof Array) {
collection = new Exhibit.Expression._Collection(root, valueType);
@@ -108,7 +108,7 @@ Exhibit.extractOptionsFromElement = function(elmt) {
Exhibit._Impl = function(database) {
this._database = (database !== null && typeof database !== "undefined") ?
database :
- (window.hasOwnProperty("database") ?
+ (typeof window["database"] !== "undefined" ?
window.database :
Exhibit.Database.create());
@@ -189,7 +189,7 @@ Exhibit._Impl.prototype.getDefaultCollection = function() {
* @param {Exhibit.Collection} c
*/
Exhibit._Impl.prototype.setCollection = function(id, c) {
- if (this._collectionMap.hasOwnProperty(id)) {
+ if (typeof this._collectionMap[id] !== "undefined") {
try{
this._collectionMap[id].dispose();
} catch(e) {
@@ -219,7 +219,7 @@ Exhibit._Impl.prototype.getComponent = function(id) {
*/
Exhibit._Impl.prototype.configure = function(configuration) {
var i, config, id;
- if (configuration.hasOwnProperty("collections")) {
+ if (typeof configuration["collections"] !== "undefined") {
for (i = 0; i < configuration.collections.length; i++) {
config = configuration.collections[i];
id = config.id;
@@ -229,7 +229,7 @@ Exhibit._Impl.prototype.configure = function(configuration) {
this.setCollection(id, Exhibit.Collection.create2(id, config, this._uiContext));
}
}
- if (configuration.hasOwnProperty("components")) {
+ if (typeof configuration["components"] !== "undefined") {
for (i = 0; i < configuration.components.length; i++) {
config = configuration.components[i];
component = Exhibit.UI.create(config, config.elmt, this._uiContext);
@@ -161,7 +161,7 @@ Exhibit.UIContext.prototype.getLensRegistry = function() {
* @returns {String|Number|Boolean|Object}
*/
Exhibit.UIContext.prototype.getSetting = function(name) {
- return this._settings.hasOwnProperty(name) ?
+ return typeof this._settings[name] !== "undefined" ?
this._settings[name] :
(this._parent !== null ? this._parent.getSetting(name) : undefined);
};
@@ -191,7 +191,7 @@ Exhibit.UIContext.prototype.putSetting = function(name, value) {
*/
Exhibit.UIContext.prototype.format = function(value, valueType, appender) {
var f;
- if (this._formatters.hasOwnProperty(valueType)) {
+ if (typeof this._formatters[valueType] !== "undefined") {
f = this._formatters[valueType];
} else {
f = this._formatters[valueType] =
@@ -266,11 +266,11 @@ Exhibit.UIContext._createWithParent = function(parent) {
Exhibit.UIContext._configure = function(context, configuration, ignoreLenses) {
Exhibit.UIContext.registerLenses(configuration, context.getLensRegistry());
- if (configuration.hasOwnProperty("collectionID")) {
+ if (typeof configuration["collectionID"] !== "undefined") {
context._collection = context._exhibit.getCollection(configuration.collectionID);
}
- if (configuration.hasOwnProperty("formats")) {
+ if (typeof configuration["formats"] !== "undefined") {
Exhibit.FormatParser.parseSeveral(context, configuration.formats, 0, {});
}
@@ -294,7 +294,7 @@ Exhibit.UIContext.registerLens = function(configuration, lensRegistry) {
var template, i;
template = configuration.templateFile;
if (typeof template !== "undefined" && template !== null) {
- if (configuration.hasOwnProperty("itemTypes")) {
+ if (typeof configuration["itemTypes"] !== "undefined") {
for (i = 0; i < configuration.itemTypes.length; i++) {
lensRegistry.registerLensForType(template, configuration.itemTypes[i]);
}
@@ -346,12 +346,12 @@ Exhibit.UIContext.registerLensFromDOM = function(elmt, lensRegistry) {
*/
Exhibit.UIContext.registerLenses = function(configuration, lensRegistry) {
var i, lensSelector;
- if (configuration.hasOwnProperty("lenses")) {
+ if (typeof configuration["lenses"] !== "undefined") {
for (i = 0; i < configuration.lenses.length; i++) {
Exhibit.UIContext.registerLens(configuration.lenses[i], lensRegistry);
}
}
- if (configuration.hasOwnProperty("lensSelector")) {
+ if (typeof configuration["lensSelector"] !== "undefined") {
lensSelector = configuration.lensSelector;
if (typeof lensSelector === "function") {
lensRegistry.addLensSelector(lensSelector);
Oops, something went wrong.

0 comments on commit 65f0af0

Please sign in to comment.