I’ve published an article on Medium.com about the ES2015 Map and WeakMap types.
- Knex and Bookshelf
- Underscore and Lodash
Obviously, the scope of each topic is greater than its chapter, but the book’s goal is to be a quick but thorough introduction to the core concepts in each framework and library. The source code is non-trivial and executable, so a reader can see concepts in action while following along in the text.
Some of the technologies covered have aged (like fine wine!), and some are much younger, but we believe that each has staying power and stands well among its peers. Between us we have used all of these technologies in our own projects and in production deployments, and while we cannot claim complete expertise, we humbly submit that, to the best of our knowledge, the information here is both sound and practical.
We sincerely hope that this book brings much value to you and your team!
This code ensures that when the method `bar` exists on the prototype for Foo, the instance implementation of `bar` added in Foo’s constructor won’t be applied. So the instance implementation is kind of like a “default implementation”. This might really only be useful if a constructor function’s prototype property changes over time, a scenario that is not likely to occur in most applications.
This came in handy for me while writing unit tests, however. I have a complex mock that creates an object for which I control both the prototype used and the constructor function. What I do not control, however, is how the object is instantiated within the module I am testing because it is ultimately instantiated through a factory function. So I can’t intercept the object and just “append” an overriding method onto the instance; the function must be added to the prototype before the object is even created by the factory function. But if a method is created on the prototype AND the constructor defines a method of the same name, the constructor function’s method will take precedence in the prototype chain. Instead, I used the conditional logic shown in the gist above to ensure that the method I define on the prototype (which I control for the purposes of the test) is the one that will be used.
There are probably much better ways to accomplish this. Conditional constructor methods reek like a code smell, so I would probably not implement anything like this in production code. For a little unit test mock, though, it is a fun thought experiment.
Right now it iterates through every jshint option and prompts the user for a setting value. Each setting has a default value, which may be chosen by simply hitting enter at the prompt. Defaults were chosen based on a simplistic criteria, one which I tend to refine a bit:
- the default for enforcing options is always TRUE
- the default for relaxing options is always FALSE
- the default for environment options is always FALSE
I also want to add some better command arguments, such as being able to specify known settings via a switch (e.g.: –use=eqeqeq=true;forin=true). The user wouldn’t be prompted for these settings since they’ve been specified already.
The –live=true switch forces hintme to screen-scrape the jshint options page and then prompt the user for the most “current” options instead of using the options.json file included with the hintme module. This is probably a tenuous way to get the most current options but it works for now.
I intend to add a suite of unit tests soon, and probably break up the code a bit. Releases < 1.0.0 should be considered rough drafts.
If you have any feature suggestions please leave a comment!
This is a brief tutorial on l33teral I recorded for appendTo’s standards and practices documentation.
This is a brief tutorial on using moment.js that I recorded for appendTo’s standards and practices documentation.
I use the bash shell with git completion on my Mac. It’s awesome except it makes my bash prompt (PS1) kind of long and ungainly:
I wanted to optimize space in my terminal, so I searched for alternative ways to display the bash prompt and found an elegant solution on askubuntu.com that reduces each directory in PWD to its first letter by evaluating the output of the `pwd` command and piping it through sed (streaming editor).
It works really well, but I wanted the last portion of the path displayed as the full directory name. I’m not familiar with sed syntax, and found myself thinking: I know how I would do this in node.js. So I copied the example, opened `.bash_profile`, and hacked up some code.
Turns out that when you invoke node with the `-e` parameter it will evaluate the string that follows. That gave me the exact prompt that I wanted:
Is it elegant? Not really. Is sed syntax more terse? Absolutely. But you know what, I do what I want and I had fun doing it. 😀
And yeah, I know, zsh.
I have published a blog post on the appendTo company blog about streams and middleware in strata.js. Strata is an HTTP server library for node.js that specializes in streaming content to and from the client.
I have written a short gist on how to create a bash function to filter out npm package dependencies when using `npm ls`. This function, when placed in .bash_profile can then be treated as a bash command. This is really helpful when you have lots npm packages installed, or those packages have lots of dependencies.