Skip to content
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ Bro(obj1).comeAtMe(obj2);
// now obj1.foo == 'bar' and obj1.yes == 'no'
```

### Deleting a key from an object
```js
var lies = { "this": { "is": { "uncool": "yes" } } };
// Not uncool!!
var bro = Bro(lies);
bro.pwn('this.is.uncool');
// => { "this": { "is": {} } }
```

### Extending Brototype!
Yes, extend me, Bro!

Expand Down
56 changes: 34 additions & 22 deletions brototype.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*global module:true, window:true, require:false, define:false*/
(function() {
(function () {
'use strict';

// Bromise... it's stronger than a Promise
Expand All @@ -10,21 +10,21 @@
}

Bromise.brototype = Bromise.prototype = {
"butWhenIdo": function(callback, context) {
"butWhenIdo": function (callback, context) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

if (this.method instanceof Function) {
var returnValue = this.method.apply(this.object, this.args);
if (returnValue) {
(callback || function(){}).call(context || this.object, returnValue);
(callback || function () { }).call(context || this.object, returnValue);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line is too long.

}
}
return context;
},

"hereComeTheErrors": function(callback) {
"hereComeTheErrors": function (callback) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

if (this.method instanceof Function) {
try {
this.method.apply(this.object, this.args);
} catch(e) {
} catch (e) {
callback(e);
}
} else {
Expand All @@ -48,11 +48,11 @@
Bro.NOWAY = false;

Bro.brototype = Bro.prototype = {
"isThatEvenAThing": function() {
"isThatEvenAThing": function () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

return this.obj !== void 0;
},

"doYouEven": function(key, callback, options) {
"doYouEven": function (key, callback, options) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

if (!(callback instanceof Function)) {
options = callback;
}
Expand All @@ -61,10 +61,10 @@
key = [key];
}
var self = this;
if (key.every(function(k) {
var bro = self.iCanHaz(k);
return (Bro(bro).isThatEvenAThing() === Bro.TOTALLY);
})) {
if (key.every(function (k) {
var bro = self.iCanHaz(k);
return (Bro(bro).isThatEvenAThing() === Bro.TOTALLY);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing 'new' prefix when invoking a constructor.

})) {
optionsBro.iDontAlways('forSure').butWhenIdo();

// Perform callback function
Expand All @@ -81,7 +81,7 @@
}
},

"iCanHaz": function(key) {
"iCanHaz": function (key) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

if (Array.isArray(key)) {
var index, value, result = [];
for (index in key) {
Expand All @@ -102,7 +102,7 @@
return item;
},

"comeAtMe": function(brobject) {
"comeAtMe": function (brobject) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

var i, prop,
bro = Bro(brobject),
keys = bro.giveMeProps(),
Expand All @@ -115,7 +115,7 @@
}
},

"giveMeProps": function() {
"giveMeProps": function () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

var key, props = [];
if (Object.keys) {
props = Object.keys(this.obj);
Expand All @@ -129,21 +129,21 @@
return props;
},

"hasRespect": function(prop) {
"hasRespect": function (prop) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

return this.obj.hasOwnProperty(prop);
},


"iDontAlways": function(methodString) {
"iDontAlways": function (methodString) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

var method = this.iCanHaz(methodString);
return new Bromise(this.obj, method, arguments);
},

"braceYourself": function(methodString) {
"braceYourself": function (methodString) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

var method = this.iCanHaz(methodString);
return new Bromise(this.obj, method, arguments);
},
"makeItHappen": function(key, value) {
"makeItHappen": function (key, value) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

var brobj = this.obj;
var props = key.split('.');
for (var i = 0; i < props.length - 1; ++i) {
Expand All @@ -154,12 +154,24 @@
}
// the deepest key is set to either an empty object or the value provided
brobj[props[props.length - 1]] = value === undefined ? {} : value;
},
"pwn": function (path) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mixed double and single quotes.

const brobj = this.obj,
Copy link
Collaborator

Choose a reason for hiding this comment

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

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

keys = path.split('.');

keys.reduce(function(acc, key, index) {
if (index === keys.length - 1) {
delete acc[key];
return true;
}
return acc[key];
}, brobj);
}
};

(function() {
(function () {
if (typeof define === 'function' && typeof define.amd === 'object') {
define(function() {
define(function () {
return Bro;
});
} else if (typeof module !== 'undefined' && module.exports) {
Expand All @@ -168,8 +180,8 @@
window.Bro = Bro;
}

if (typeof(angular) !== 'undefined') {
angular.module('brototype', []).factory('Bro', function() { return Bro; });
if (typeof (angular) !== 'undefined') {
angular.module('brototype', []).factory('Bro', function () { return Bro; });
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line is too long.

}
})();
})();
Loading