JavaScript Promises No I am not talking the promise that JavaScript will fix everything if you use it. I don't even believe that ;) I am talking about the concept of a promise object that several JavaScript libraries use (including AngularJS, jQuery, Dojo and WinJS). A promise is a pattern for handling asynchronous operations. In this example you can see the jQuery uses the success property of the settings object to specify the callback. The promise pattern sets out to simplify this process. What is interesting here, is that the object that ajax returns is the xhr object which implements the promise pattern so we can call then as seen here. Because many libraries are starting to take on the promise pattern, handling asynchronous operations should be easier no matter what code you're writing (e.g. One important key to the pattern is that the then function can accept two functions. Let's see how using a promise looks. You can play with these examples in JSFiddle and see what you can make happen.
JSbooks - free javascript books timjacobi/angular-education Promise-ы в AngularJS Одной из ключевых составляющих практически любого веб-приложения является взаимодействие с сервером. В больших приложениях это далеко не один запрос. При этом запросы часто необходимо объединять для последовательного или параллельного выполнения, а часто сочетать и то и другое. Кроме того, большие приложения обычно имеют многослойную архитектуру — обертка над RESTFul API => бизнес-сущности => более комплексная бизнес-логика (разбиение условно для примера). И на каждом слое необходимо принять данные в одном формате и передать на следующий слой уже в другом. Вот со всеми этими задачами могут помочь справиться Promise-ы. За подробностями добро пожаловать под кат. Promise-ы предоставляют интерфейс для взаимодействия с объектами, содержащими результат выполнения некоторой операции, время окончания которой неизвестно. Кроме того, promise-ы можно объединять как для последовательного, так и для параллельного исполнения. Итак, что из себя представляет promise? Что в AngularJS вернет вам promise?
jQuery Validation Plugin | Form validation with jQuery Three.js and Babylon.js: a Comparison of WebGL Frameworks Today’s web browsers have come a long way since the days of Sir Tim Berners-Lee and his Nexus software. Thanks to fantastic JavaScript APIs like WebGL, modern browsers are fully capable of rendering advanced 2D and 3D graphics without help from third-party plugins. By leveraging the horsepower of dedicated graphics processors, WebGL gives our web pages access to dynamic shading and realistic physics. As you might have guessed, such powerful APIs typically come with a drawback. The humble origins of 3D frameworks The ever popular Three.js along with the newer Babylon.js offer web developers an abstract foundation for crafting feature rich WebGL creations ranging from animated logos to fully interactive 3D games. Three.js got its start back in April of 2009 and was originally written in ActionScript before being translated to JavaScript. Babylon.js, being the relative newcomer, broke onto the scene in the summer of 2013. A subtle difference in design Three.js: Babylon.js:
AngularJS and scope.$apply — Jim Hoskins If you’ve written a non-trivial amount of code in AngularJS, you may have come across the $scope.$apply() method. On the surface, it may seem like just a method you call to get your bindings to update. To really understand when to use $apply, it’s good to know exactly why we need to use it, so let’s dive in! JavaScript is Turn Based The JavaScript code we write doesn’t all run in one go, instead it executes in turns. Instead, whenever there is a task that takes some amount of time, such as an Ajax request, waiting for a click event, or setting a timeout, we set up a callback function and finish our current turn. Let’s look at an example JavaScript file: var button = document.getElementById('clickMe'); function buttonClicked () { alert('the button was clicked'); } button.addEventListener('click', buttonClicked); function timerComplete () { alert('timer complete'); } setTimeout(timerComplete, 2000); When the JavaScript code is loaded, that is a single turn. How do we update bindings? $scope.
An Introduction to AngularJS Forms Validation