Skip to content

Commit

Permalink
fix #4 Optimize the inital object.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Sep 20, 2018
1 parent 0602413 commit 89226ca
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function toArray(value) {
return Array.prototype.slice.call(value);
}
function Cookie(){
if(!(this instanceof Cookie)) {
return new Cookie()
};
if(!(this instanceof Cookie)) {
return new Cookie()
};
}
Cookie.prototype = {
get: function(name){
Expand Down Expand Up @@ -76,16 +76,19 @@ Cookie.prototype = {
}
};

var cookie = function(name, value, options){
let _Cookie = null;

const cookie = function(name, value, options){
var argm = arguments;
if (argm.length === 0) return Cookie().all();
if (argm.length === 1 && name === null) return Cookie().clear();
if (argm.length === 2 && !value) return Cookie().clear(name);
if (typeof(name) == 'string'&&!value) return Cookie().get(name);
if (!_Cookie) _Cookie = Cookie();
if (argm.length === 0) return _Cookie.all();
if (argm.length === 1 && name === null) return _Cookie.clear();
if (argm.length === 2 && !value) return _Cookie.clear(name);
if (typeof(name) == 'string'&&!value) return _Cookie.get(name);
if (isPlainObject(name) || (argm.length>1&&name&&value))
return Cookie().set(name, value, options);
if (value === null) return Cookie().remove(name);
return Cookie().all();
return _Cookie.set(name, value, options);
if (value === null) return _Cookie.remove(name);
return _Cookie.all();
}
for (var a in Cookie.prototype) cookie[a] = Cookie.prototype[a];
for (const a in Cookie.prototype) cookie[a] = Cookie.prototype[a];
return cookie;

0 comments on commit 89226ca

Please sign in to comment.