Skip to content

Commit

Permalink
Removing Object.prototype.fillDefaults
Browse files Browse the repository at this point in the history
  • Loading branch information
kopiro committed Nov 5, 2018
1 parent 6fe2b40 commit 90bd7ed
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 223 deletions.
22 changes: 4 additions & 18 deletions main.js
@@ -1,7 +1,7 @@
const EventEmitter = require('events');
const fs = require('fs');

const { getHostFromWebservice, cookiesToStr, parseCookieStr, fillCookies, newId, indexOfKey, fillMethods } = require("./resources/helper");
const { getHostFromWebservice, cookiesToStr, parseCookieStr, fillCookies, newId, indexOfKey, fillMethods, fillDefaults} = require("./resources/helper");

Array.prototype.indexOfKey = indexOfKey;

Expand Down Expand Up @@ -41,7 +41,7 @@ class iCloud extends EventEmitter {

function sessionInit(session) {
// Session Validation. This adds default properties to the session that doesn't exists
session = session.fillDefaults({
session = fillDefaults(session, {
username: username,
password: password,
auth: {
Expand Down Expand Up @@ -96,7 +96,7 @@ class iCloud extends EventEmitter {
});

// Session object is validated. Now, the (self) instance will be extended with session's properties using the fill defaults function.
self = self.fillDefaults(session);
self = fillDefaults(self, session);

Object.keys(self.apps).forEach(function(appPropName) {
if ("instanceName" in self.apps[appPropName]) {
Expand Down Expand Up @@ -350,18 +350,4 @@ class iCloud extends EventEmitter {

}

module.exports = iCloud;

// Small self made fillDefaults method to fill an object with default properties

Object.prototype.fillDefaults = function(defaults) {
Object.keys(defaults).forEach(key => {
if (!(key in this)) {
this[key] = defaults[key];
}
else if (typeof defaults[key] == "object" && defaults[key] != null) {
this[key] = this[key].fillDefaults(defaults[key]);
}
});
return this;
}
module.exports = iCloud;

0 comments on commit 90bd7ed

Please sign in to comment.