hybridgroup/cylon — pull request #204 by stewart (2014-06-17 23:05:10+00:00)
Title: Add #fetch Utility function

The `#fetch` utility acts in (roughly) the same way as Ruby's `Hash#fetch` function:

```javascript
var object = { property: "hello world" };
Utils.fetch(object, "property");
//=> "hello world"

Utils.fetch(object, "notaproperty", "default value");
//=> "default value"

var notFound = function(prop) { return prop + " not found!" };
Utils.fetch(object, "notaproperty", notFound)
// "notaproperty not found!"

var badFallback = function(prop) { prop + " not found!" };
Utils.fetch(object, "notaproperty", badFallback)
// Error: no return value from provided callback function

Utils.fetch(object, "notaproperty");
// Error: key not found: "notaproperty"
```

This addition can hopefully be used to make constructors more rigorous and help to prevent a few classes of errors.