decoupling

When should I use jQuery deferred's “then” method and when should I use the “pipe” method?

匆匆过客 提交于 2019-11-26 18:11:47
jQuery's Deferred has two functions which can be used to implement asynchronous chaining of functions: then() deferred.then( doneCallbacks, failCallbacks ) Returns: Deferred doneCallbacks A function, or array of functions, called when the Deferred is resolved. failCallbacks A function, or array of functions, called when the Deferred is rejected. pipe() deferred.pipe( [doneFilter] [, failFilter] ) Returns: Promise doneFilter An optional function that is called when the Deferred is resolved. failFilter An optional function that is called when the Deferred is rejected. I know then() has been

Best practice for embedding arbitrary JSON in the DOM?

一个人想着一个人 提交于 2019-11-26 12:37:20
问题 I\'m thinking about embedding arbitrary JSON in the DOM like this: <script type=\"application/json\" id=\"stuff\"> { \"unicorns\": \"awesome\", \"abc\": [1, 2, 3] } </script> This is similar to the way one might store an arbitrary HTML template in the DOM for later use with a JavaScript template engine. In this case, we could later retrieve the JSON and parse it with: var stuff = JSON.parse(document.getElementById(\'stuff\').innerHTML); This works, but is it the best way? Does this violate

When should I use jQuery deferred&#39;s “then” method and when should I use the “pipe” method?

谁说胖子不能爱 提交于 2019-11-26 08:54:23
问题 jQuery\'s Deferred has two functions which can be used to implement asynchronous chaining of functions: then() deferred.then( doneCallbacks, failCallbacks ) Returns: Deferred doneCallbacks A function, or array of functions, called when the Deferred is resolved. failCallbacks A function, or array of functions, called when the Deferred is rejected. pipe() deferred.pipe( [doneFilter] [, failFilter] ) Returns: Promise doneFilter An optional function that is called when the Deferred is resolved.

Type List vs type ArrayList in Java

二次信任 提交于 2019-11-25 22:23:17
问题 (1) List<?> myList = new ArrayList<?>(); (2) ArrayList<?> myList = new ArrayList<?>(); I understand that with (1), implementations of the List interface can be swapped. It seems that (1) is typically used in an application regardless of need (myself I always use this). I am wondering if anyone uses (2)? Also, how often (and can I please get an example) does the situation actually require using (1) over (2) (i.e. where (2) wouldn\'t suffice..aside coding to interfaces and best practices etc.)