1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-02-05 13:40:02 +00:00

Got rid of some potentially dodgy hasOwnProperty() calls

This commit is contained in:
Jeremy Ruston 2012-05-09 08:51:16 +01:00
parent 557a7b0eba
commit d99b70e0b2
6 changed files with 12 additions and 12 deletions

View File

@ -68,7 +68,7 @@ Dependencies.prototype.hasChanged = function(changes,contextTiddlerTitle) {
return true; return true;
} }
for(var c in changes) { for(var c in changes) {
if(this.tiddlers.hasOwnProperty(c)) { if($tw.utils.hop(this.tiddlers,c)) {
return true; return true;
} }
} }

View File

@ -151,7 +151,7 @@ exports.executeMacro = function() {
exports.refreshInDom = function(changes) { exports.refreshInDom = function(changes) {
var needChildrenRefresh = true; // Avoid refreshing the children nodes if we don't need to var needChildrenRefresh = true; // Avoid refreshing the children nodes if we don't need to
// If the state tiddler has changed then reset the open state // If the state tiddler has changed then reset the open state
if(this.hasParameter("state") && changes.hasOwnProperty(this.params.state)) { if(this.hasParameter("state") && $tw.utils.hop(changes,this.params.state)) {
this.isOpen = this.getOpenState(); this.isOpen = this.getOpenState();
} }
// Render the children if the slider is open and we don't have any children yet // Render the children if the slider is open and we don't have any children yet

View File

@ -39,7 +39,7 @@ exports.handleEvent = function(event) {
template = this.hasParameter("defaultViewTemplate") ? this.params.defaultViewTemplate : "ViewTemplate"; template = this.hasParameter("defaultViewTemplate") ? this.params.defaultViewTemplate : "ViewTemplate";
storyTiddler = this.wiki.getTiddler(this.params.story); storyTiddler = this.wiki.getTiddler(this.params.story);
story = {tiddlers: []}; story = {tiddlers: []};
if(storyTiddler && storyTiddler.fields.hasOwnProperty("text")) { if(storyTiddler && $tw.utils.hop(storyTiddler.fields,"text")) {
story = JSON.parse(storyTiddler.fields.text); story = JSON.parse(storyTiddler.fields.text);
} }
story.tiddlers.unshift({title: event.navigateTo, template: template}); story.tiddlers.unshift({title: event.navigateTo, template: template});
@ -52,7 +52,7 @@ exports.handleEvent = function(event) {
template = this.hasParameter("defaultEditTemplate") ? this.params.defaultEditTemplate : "EditTemplate"; template = this.hasParameter("defaultEditTemplate") ? this.params.defaultEditTemplate : "EditTemplate";
storyTiddler = this.wiki.getTiddler(this.params.story); storyTiddler = this.wiki.getTiddler(this.params.story);
story = {tiddlers: []}; story = {tiddlers: []};
if(storyTiddler && storyTiddler.fields.hasOwnProperty("text")) { if(storyTiddler && $tw.utils.hop(storyTiddler.fields,"text")) {
story = JSON.parse(storyTiddler.fields.text); story = JSON.parse(storyTiddler.fields.text);
} }
for(t=0; t<story.tiddlers.length; t++) { for(t=0; t<story.tiddlers.length; t++) {
@ -81,14 +81,14 @@ exports.handleEvent = function(event) {
storyTiddler = this.wiki.getTiddler(this.params.story); storyTiddler = this.wiki.getTiddler(this.params.story);
story = {tiddlers: []}; story = {tiddlers: []};
storyTiddlerModified = false; storyTiddlerModified = false;
if(storyTiddler && storyTiddler.fields.hasOwnProperty("text")) { if(storyTiddler && $tw.utils.hop(storyTiddler.fields,"text")) {
story = JSON.parse(storyTiddler.fields.text); story = JSON.parse(storyTiddler.fields.text);
} }
for(t=0; t<story.tiddlers.length; t++) { for(t=0; t<story.tiddlers.length; t++) {
storyRecord = story.tiddlers[t]; storyRecord = story.tiddlers[t];
if(storyRecord.title === event.tiddlerTitle && storyRecord.template !== template) { if(storyRecord.title === event.tiddlerTitle && storyRecord.template !== template) {
tiddler = this.wiki.getTiddler(storyRecord.title); tiddler = this.wiki.getTiddler(storyRecord.title);
if(tiddler && tiddler.fields.hasOwnProperty("draft.title")) { if(tiddler && $tw.utils.hop(tiddler.fields,"draft.title")) {
// Save the draft tiddler as the real tiddler // Save the draft tiddler as the real tiddler
this.wiki.addTiddler(new $tw.Tiddler(tiddler,{title: tiddler.fields["draft.title"],"draft.title": undefined, "draft.of": undefined})); this.wiki.addTiddler(new $tw.Tiddler(tiddler,{title: tiddler.fields["draft.title"],"draft.title": undefined, "draft.of": undefined}));
// Remove the draft tiddler // Remove the draft tiddler

View File

@ -117,7 +117,7 @@ Macro.prototype.parseMacroParamString = function(paramString) {
}; };
Macro.prototype.hasParameter = function(name) { Macro.prototype.hasParameter = function(name) {
return this.params.hasOwnProperty(name); return $tw.utils.hop(this.params,name);
}; };
Macro.prototype.cloneContent = function() { Macro.prototype.cloneContent = function() {

View File

@ -75,7 +75,7 @@ var ArgParser = function(argString,options) {
} }
if(n.evaluated === true) { if(n.evaluated === true) {
n = "{{" + n.string + "}}"; n = "{{" + n.string + "}}";
} else if (typeof n === "object" && n.hasOwnProperty("string")) { } else if (typeof n === "object" && $tw.utils.hop(n,"string")) {
n = n.string; n = n.string;
} }
this.byPos.push({n:n, v:v}); this.byPos.push({n:n, v:v});
@ -90,7 +90,7 @@ var ArgParser = function(argString,options) {
for(var t=0; t<this.byPos.length; t++) { for(var t=0; t<this.byPos.length; t++) {
n = this.byPos[t].n; n = this.byPos[t].n;
v = this.byPos[t].v; v = this.byPos[t].v;
if(this.byName.hasOwnProperty(n)) if($tw.utils.hop(this.byName,n))
this.byName[n].push(v); this.byName[n].push(v);
else else
this.byName[n] = [v]; this.byName[n] = [v];

View File

@ -62,7 +62,7 @@ exports.touchTiddler = function(title,isDeleted) {
this.changedTiddlers[title][isDeleted ? "deleted" : "modified"] = true; this.changedTiddlers[title][isDeleted ? "deleted" : "modified"] = true;
// Increment the change count // Increment the change count
this.changeCount = this.changeCount || {}; this.changeCount = this.changeCount || {};
if(this.changeCount.hasOwnProperty(title)) { if($tw.utils.hop(this.changeCount,title)) {
this.changeCount[title]++; this.changeCount[title]++;
} else { } else {
this.changeCount[title] = 1; this.changeCount[title] = 1;
@ -86,7 +86,7 @@ exports.touchTiddler = function(title,isDeleted) {
exports.getChangeCount = function(title) { exports.getChangeCount = function(title) {
this.changeCount = this.changeCount || {}; this.changeCount = this.changeCount || {};
if(this.changeCount.hasOwnProperty(title)) { if($tw.utils.hop(this.changeCount,title)) {
return this.changeCount[title]; return this.changeCount[title];
} else { } else {
return 0; return 0;
@ -227,7 +227,7 @@ exports.getCacheForTiddler = function(title,cacheName,initializer) {
// Clear all caches associated with a particular tiddler // Clear all caches associated with a particular tiddler
exports.clearCache = function(title) { exports.clearCache = function(title) {
this.caches = this.caches || {}; this.caches = this.caches || {};
if(this.caches.hasOwnProperty(title)) { if($tw.utils.hop(this.caches,title)) {
delete this.caches[title]; delete this.caches[title];
} }
}; };