letsgetrandy / brototype Goto Github PK
View Code? Open in Web Editor NEWBro, do you even?
License: MIT License
Bro, do you even?
License: MIT License
In this readme, these two examples are provided:
var myURL;
Bro(app)
.iDontAlways('config.environment.buildURL')
.butWhenIdo(function(buildURL){
myURL = buildURL('dev');
});
Bro(object)
.iDontAlways('method')
.butWhenIdo(function(returnVal) {
console.log('object.method() returned ', returnVal);
});
As far as I can tell, both are functionally identical and call a nested method. In the first example, the function is passed as a callback inside butWhenIdo
and then called, whereas in the second example, the return value of the function is passed.
Looking at the code, this looks like the pertinent section:
if (returnValue) {
(callback || function(){}).call(context || this.object, returnValue);
}
Am I correct in interpreting this that if the nested function returns a value, the return value is passed to the callback, and if it does not return a value, the function is passed to the callback?
If so, that seems like it may be of risky design - you're equally likely to call the function twice by accident as you are to expect it to be a function and instead have it be the returned value? If not, perhaps the readme can be improved to clarify the behavior?
Just don't.
Thanks!
iCanHaz() could be made to work recursively. Currently:
var rentProblems = {
the: {
rent: 'is too damn high'
}
};
Bro( rentProblems ).iCanHaz( 'rent' );
// -> rent is not defined
It might be useful to allow the user to pass in a recursive
boolean argument to search an entire object for a key, like:
Bro( rentProblems ).iCanHaz( 'rent', Bro.TOTALLY );
// -> 'is too damn high'
// or return an array of full paths that match the key and allow the user to decide when to get the value from the path:
// -> [rentProblems.the.rent]
Looking at this example, the callback for subproperty is never called, though the readme suggests that it should work? I don't think this is related to #47, because looking at the commit history, before there was no options
at all, and after optionsBro
was added (which, does what exactly?), there's still no support for callback.
var Bro = require("brototype")
var object = {
property: {
subproperty: "foo"
}
}
Bro(object)
.doYouEven('property.subproperty', function(subproperty) {
console.log('subproperty: ', subproperty);
});
If you like, I can look into implementing this, but I'm skeptical that I'll implement it the way you guys want? Here's a test that should pass if it works:
it('should pass the nested property to a callback function', function(done) {
var a = {
foo: 'bar'
}
Bro(a).doYouEven('foo', function(foo) {
assert.equal(foo, 'bar');
done();
})
});
Yo, Bro... are you using Brototype in the wild? If so, drop a comment in here so we can tell the world about how awesome it is!
var a = {}
a['shit.bro'] = {5: 'total shit'};
???
This is a useful program using an ass-backwards and idiotic naming scheme. Code is meant to be used, not laughed at and burnt in a fire. If you keep writing libraries for illiterate 12-year-olds, I will have to create a renamed fork.
When passing an array of paths into iCanHaz
, I'd like to get back an array containing values for paths that matched.
Please publish this package on npm. We actually want to use it :)
Hello, i created a small util for app
export const hasIn = (obj = {}, path) => {
return bro(obj).doYouEven(path);
};
Then i try this code:
!hasIn(post, 'test.0.test')
post isn't undefined, post = { test: null }
After i have the message in console with text:
Cannot read property '0' of null
Can you help me resolve this problem?
I wish there was a function Bro.pwn
which deletes a key in an object. Like so:
Bro(object).pwn('key')
I think my words speak for themselves.
I finally got it working.
I got rid of the module pattern on one of my projects, and it now works as an angular module that provides a service, as well as in node and amd. See https://github.com/deltreey/wildstring/blob/master/wildstring.js
I use brototype with angular, which requires me to use $window and if I have it as a module dependency it doesn't get listed, which is also ugly. I'm wondering if you'd be amicable to me doing a similar pattern here. I'll attach a pull request from a branch I'll make.
I got the idea from here http://snook.ca/archives/javascript/no-love-for-module-pattern if you're interested. I love how clean and easy to read brototype's code is and I think this will make it even easier to understand.
Swallow all of the errors.
Here come the errors:
ReferenceError: exports is not defined
Expect conditionals to handle this error by falling back to window
Bro(app)
.iDontAlways('config.environment.buildURL')
.butWhenIdo(function(buildURL){
myURL = buildURL('dev');
});
This is awesome, but sometimes it's great to not have to check the property again to handle an 'else' exception. Something like:
Bro(app)
.iDontAlways('config.environment.buildURL')
.butWhenIdo(function(buildURL){
myURL = buildURL('dev');
})
.butIfIdont(function() {
// do other stuff
});
Tried to wire in something like this, but it blew up when trying to add in the fallback function.
I tried:
Bro(app).doYouEven('xxx.yyy')
That produced:
Uncaught ReferenceError: app is not defined
Took me awhile to realize this bro, .butWhenIdo
is not consistently camelCased (do
is lowercase when it should be uppercase). You should totally fix that, or add a note to the readme pointing it out.
Getting a 403
'Cause, I mean... then you could take full advantage of brototypal inheritance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.