Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add if (!value.hasOwnProperty(vKey)) continue; that occurred bugs! #236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
node_modules
.idea
*.swp
*.log

11 changes: 4 additions & 7 deletions lib/memcached.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ var curry = Utils.curry;
function Client (args, options) {
var servers = []
, weights = {}
, regular = 'localhost:11211'
, key;
, regular = 'localhost:11211';

// Parse down the connection arguments
switch (Object.prototype.toString.call(args)) {
Expand Down Expand Up @@ -112,8 +111,7 @@ Client.config = {
nMemcached.prototype.__proto__ = require('events').EventEmitter.prototype;

var memcached = nMemcached.prototype
, privates = {}
, undefined;
, privates = {};

// Creates or generates a new connection for the give server, the callback
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sry, this is because of my JSHint.

#the never used variables#

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, but re-defining a scoped undefined variable actually makes checking against undefined safe as you can override the global undefined variable with things.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the redefining undefined part is obsolete in node and other modern runtimes:

> undefined = 'foo'
'foo'
> undefined
undefined

// will receive the connection if the operation was successful
Expand Down Expand Up @@ -319,7 +317,7 @@ Client.config = {
var S = {
serverAddress: server,
tokens: server.split(':').reverse()
}
};
var message = error || 'Unable to connect to server';
memcached.connectionIssue(message, S);
return query.callback && memcached.makeCallback(query.callback,new Error(message));
Expand Down Expand Up @@ -706,8 +704,7 @@ Client.config = {
, dataSet
, resultSet
, metaData
, err = []
, tmp;
, err = [];

while(S.bufferArray.length && privates.allCommands.test(S.bufferArray[0])) {
token = S.bufferArray.shift();
Expand Down
2 changes: 2 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports.validateArg = function validateArg (args, config) {
}
if (!err && key === 'key') {
for (var vKey in value) {
if (!value.hasOwnProperty(vKey)) continue;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as comment below.

var vValue = value[vKey];
var result = validateKeySize(config, vKey, vValue);
if (result.err) {
Expand Down Expand Up @@ -111,6 +112,7 @@ exports.fuse = function fuse (target, handlers) {
// merges a object's proppertys / values with a other object
exports.merge = function merge (target, obj) {
for (var i in obj) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might just make more sense to use Object.keys here instead so it solve the problem that hasOwnProperty would resolve and introduce an performance boost.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, the formal way of for ... in in JSHint is just wrapping the body in if(foo.hasOwnProperty(bar)).

If you don't, JSHint will show a warning. And of cause, this place made some bugs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've become a big fan of Object.keys over the years as well. It's pretty fast these days and you'll be iterating over an array.

if (!obj.hasOwnProperty(i)) continue;
target[i] = obj[i];
}

Expand Down