Skip to content

Commit

Permalink
fixed #115 don't directly use hasOwnProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaoran authored and mroderick committed Dec 14, 2020
1 parent c9aa139 commit 83648dd
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

(function (root, factory){
'use strict';

var PubSub = {};
root.PubSub = PubSub;
factory(PubSub);
Expand All @@ -24,7 +24,7 @@
else if (typeof define === 'function' && define.amd){
define(function() { return PubSub; });
/* eslint-enable no-undef */
}
}

}(( typeof window === 'object' && window ) || this, function (PubSub){
'use strict';
Expand All @@ -37,7 +37,7 @@
var key;

for (key in obj){
if ( obj.hasOwnProperty(key) ){
if ( Object.prototype.hasOwnProperty.call(obj, key) ){
return true;
}
}
Expand Down Expand Up @@ -73,12 +73,12 @@
callSubscriber = immediateExceptions ? callSubscriberWithImmediateExceptions : callSubscriberWithDelayedExceptions,
s;

if ( !messages.hasOwnProperty( matchedMessage ) ) {
if ( !Object.prototype.hasOwnProperty.call( messages, matchedMessage ) ) {
return;
}

for (s in subscribers){
if ( subscribers.hasOwnProperty(s)){
if ( Object.prototype.hasOwnProperty.call(subscribers, s)){
callSubscriber( subscribers[s], originalMessage, data );
}
}
Expand All @@ -105,7 +105,7 @@

function hasDirectSubscribersFor( message ) {
var topic = String( message ),
found = Boolean(messages.hasOwnProperty( topic ) && hasKeys(messages[topic]));
found = Boolean(Object.prototype.hasOwnProperty.call( messages, topic ) && hasKeys(messages[topic]));

return found;
}
Expand Down Expand Up @@ -182,15 +182,15 @@
message = (typeof message === 'symbol') ? message.toString() : message;

// message is not registered yet
if ( !messages.hasOwnProperty( message ) ){
if ( !Object.prototype.hasOwnProperty.call( messages, message ) ){
messages[message] = {};
}

// forcing token as String, to allow for future expansions without breaking usage
// and allow for easy use as key names for the 'messages' object
var token = 'uid_' + String(++lastUid);
messages[message][token] = func;

// return token for unsubscribing
return token;
};
Expand Down Expand Up @@ -236,13 +236,13 @@
PubSub.clearSubscriptions = function clearSubscriptions(topic){
var m;
for (m in messages){
if (messages.hasOwnProperty(m) && m.indexOf(topic) === 0){
if (Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0){
delete messages[m];
}
}
};

/**
/**
Count subscriptions by the topic
* @function
* @public
Expand All @@ -253,15 +253,15 @@
var m;
var count = 0;
for (m in messages){
if (messages.hasOwnProperty(m) && m.indexOf(topic) === 0){
if (Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0){
count++;
}
}
return count;
};

/**

/**
Gets subscriptions by the topic
* @function
* @public
Expand All @@ -271,7 +271,7 @@
var m;
var list = [];
for (m in messages){
if (messages.hasOwnProperty(m) && m.indexOf(topic) === 0){
if (Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0){
list.push(m);
}
}
Expand Down Expand Up @@ -302,15 +302,15 @@
var descendantTopicExists = function(topic) {
var m;
for ( m in messages ){
if ( messages.hasOwnProperty(m) && m.indexOf(topic) === 0 ){
if ( Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0 ){
// a descendant of the topic exists:
return true;
}
}

return false;
},
isTopic = typeof value === 'string' && ( messages.hasOwnProperty(value) || descendantTopicExists(value) ),
isTopic = typeof value === 'string' && ( Object.prototype.hasOwnProperty.call(messages, value) || descendantTopicExists(value) ),
isToken = !isTopic && typeof value === 'string',
isFunction = typeof value === 'function',
result = false,
Expand All @@ -322,7 +322,7 @@
}

for ( m in messages ){
if ( messages.hasOwnProperty( m ) ){
if ( Object.prototype.hasOwnProperty.call( messages, m ) ){
message = messages[m];

if ( isToken && message[value] ){
Expand All @@ -334,7 +334,7 @@

if (isFunction) {
for ( t in message ){
if (message.hasOwnProperty(t) && message[t] === value){
if (Object.prototype.hasOwnProperty.call(message, t) && message[t] === value){
delete message[t];
result = true;
}
Expand Down

0 comments on commit 83648dd

Please sign in to comment.