Use the has API #19
Comments
Thanks for the report! The problem with the suggested implementation is that it's not strictly equivalent to I can contribute JSON 3's feature tests to the I'm not familiar with how Dojo's optimizer works, so please forgive me if I'm misunderstanding the thrust of the issue. |
Actually while has.js and dojo introduced the has API, from an optimizer perspective any library can implement it. For example poly.js uses it and Modernizr has an issue open to make use of it as well. It is possible to configure the r.js and dojo optimizers to build for browsers with particular features. So instead of having a run-time decision, you can make the decision at build-time. For example... // build.js
( {
baseUrl: '.',
...
has: {
// Build for browsers that have valid JSON implementations
'json-parse': true,
'json-stringify': true,
'json': true
}
} ) ... So code written like this... ...
if( has( 'json-parse' ) ){
// Use native JSON.parse
} else {
// Use polyfill
}
... ... becomes... ...
// Use native JSON.parse
... |
Ah, I see. Thanks very much for clarifying! Does c54a4d7 look solid to you? |
Looks good to me. |
Use the has API instead of
stringifySupported
andparseSupported
in order to take advantage of has-aware AMD optimizers, like r.js and dojo.The text was updated successfully, but these errors were encountered: