In JavaScript, this is a big no-no:
function Set() {
}
Set.prototype.content = [];| <div class="body"> | |
| {{#if comment }} | |
| <div class="comment"> | |
| {{{ comment.value }}} | |
| </div> | |
| {{#if comment.canMakePrivate}} | |
| <div class="link_light make-private"> | |
| <em data-action="make-private" data-audit-id="{{../id}}">{{comment.makePrivateActionLabel}}</em> | |
| </div> | |
| {{/if}} |
Cory Foy recently wrote an article entitled, Procedural Polymorphism: Is your code really telling you to use an if statement?. Corey Haines has been talking about this same topic for a while. Sandi Metz covers the topic in Practical Object-Oriented Design in Ruby. Ben Rady and Rod Coffin discussed using the Null-Object pattern instead of an if statement in Continuous Testing with Ruby, Rails, and JavaScript.
That is, very smart people whom I admire agree that, in general,
class DeadCellI have an object that acts as a "directory" or a "library" of data -- for example, a list of the time zones on the machine. Because there is only one such list, and because the list is static, this object is a good candidate for a global, immutable object. For example, in Ruby:
class TimeWithOffset
ALL_TIME_ZONES = {
"Midway Island": -660,
# ...
"Brasilia": -180,
# ...Recently, I needed to extract a number of directories from a git project each into their own projects. The original directory structure looked like
project/
subprojects/
Foo/
Bar/
Baz
| // Array Iteration: | |
| myArray = [ 'foo' ]; | |
| myArray.forEach(function(x) { console.log(x); }); | |
| // prints "foo" | |
| // Object Keys: | |
| myObject = { foo: 'bar', baz: 'quux' }; | |
| Object.keys(myObject); // [ "foo", "baz" ] | |
| // Object Iteration Helper (context is optional) |
| # from our office | |
| $ dig int.tangocard.com | |
| ; <<>> DiG 9.7.3-P3 <<>> int.tangocard.com | |
| ;; global options: +cmd | |
| ;; Got answer: | |
| ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14686 | |
| ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 13, ADDITIONAL: 7 | |
| ;; QUESTION SECTION: |
| # Our starting point: | |
| # a Rack endpoint that performs HTTP Basic auth. | |
| class SignInEndpoint | |
| def call(env) | |
| email, password = *credentials(env) | |
| user = User.authenticate(email, password) | |
| if user.nil? || user.deleted? | |
| respond_with_error 'Invalid credentials' |
| # Usage | |
| # rake check_file_widths | |
| # rake check_file_widths[120] | |
| # rake check_file_widths[80, "app/**/*.rb"] | |
| # | |
| # Arguments: | |
| # * width - the max width; defaults to 80 | |
| # * paths - the list of files to check; defaults to | |
| # {app,lib}/**/*.{js,rb,scss,coffee,erb} | |
| desc "Ensure there are no overly long lines" |