background preloader

JS interesting articles

Facebook Twitter

TypeScript AMD with RequireJS Tutorial. Posted by robert | Filed under TypeScript In this TypeScript RequireJS tutorial I will show you how to setup AMD classes, setup your config file and how to use RequireJS plugins with TypeScript. TypeScript AMD Classes Below is how we setup a AMD class that we can use with RequireJS. The most important part is to have the export statement below the class itself and to equal the class you created. Next we want to import that Base.ts AMD TypeScript class into another class. You can see below how we have an import statement that will bring in our Base class. Once you have your RequireJS config file setup to load jQuery then you can do the following in your classes. RequireJS Plugins TypeScript Seems like this is an undocumented TypeScript feature. If you need to add multiple plugins into the file you will need to put all the /// <amd-dependency path=”” /> above the require code like: RequireJS Config & Bootstrap Classes Here is my RequireJS config file(AppConfig.ts):

Typescript - Invoke the text plugin from requirejs mapping. TypeScript: compiling removes unreferenced imports. Experience of converting of Javascript project into Typescript. As you probably know, Typescript 1.5 was officially released couple of days ago (to be precise, it was on 18. 7. 2015 based on github release notes). When you combine it together with the facts that Microsoft open-sourced the language and partnered with Google to make Typescript main development language for upcoming Angular 2.0, you will end up with some crazy hype being hyped even more than we’re used to… (our lovely Javascript became pretty intense lately) Are you Hyped yet ?!

Good ! But let’s take it slow for now… The chances are pretty high that the project you’re currently working on professionally is being implemented using only vanilla Javascript or ES6 if you’re lucky. The Basics Typescript, while being superset of Javascript, still isn’t the Javascript itself. But what if the initial code base conversion is achievable with a minimal downtime ?

The Context As for the stack, it’s a Angular JS (1.4) portal with JavaEE back-end (nothing surprising here) but there is a twist. Testing. TypeScript vs. CoffeeScript vs. ES6. 16 JavaScript Concepts JavaScript Professionals Must Know Well. (Essential JavaScript Concepts for Modern JavaScript Development ) If you plan to work as JavaScript Professional, you must know some JavaScript concepts and JavaScript-related web-development technologies, particularly as a modern JavaScript developer. If you know the 16 concepts enumerated below, you have the skill necessary to build world-class modern JavaScript web applications, and you are set for the near future—0 to 3 years. I will expound on each of these sixteen concepts, and I am hopeful all of us will have become better JavaScript programmers by the time we get through all of them. I have completed most of the 16 concepts with just a few more to go, so keep reading and learning.

And sign up for the newsletter to get the latest updates. I trust you have learned JavaScript properly or you already know JavaScript enough to build a simple JavaScript-only web application. JavaScript Module Pattern: In-Depth. The module pattern is a common JavaScript coding pattern. It’s generally well understood, but there are a number of advanced uses that have not gotten a lot of attention. In this article, I’ll review the basics and cover some truly remarkable advanced topics, including one which I think is original. The Basics We’ll start out with a simple overview of the module pattern, which has been well-known since Eric Miraglia (of YUI) first blogged about it three years ago.

Anonymous Closures This is the fundamental construct that makes it all possible, and really is the single best feature of JavaScript. (function () { // ... all vars and functions are in this scope only // still maintains access to all globals }()); Notice the () around the anonymous function. Global Import JavaScript has a feature known as implied globals. Luckily, our anonymous function provides an easy alternative. (function ($, YAHOO) { // now have access to globals jQuery (as $) and YAHOO in this code }(jQuery, YAHOO)); Private Members in JavaScript. Douglas Crockford JavaScript is the world's most misunderstood programming language.

Some believe that it lacks the property of information hiding because objects cannot have private instance variables and methods. But this is a misunderstanding. JavaScript objects can have private members. Here's how. Objects JavaScript is fundamentally about objects. If a value is a function, we can consider it a method. Objects can be produced by constructors, which are functions which initialize objects. Public The members of an object are all public members. In the constructor This technique is usually used to initialize public instance variables.

Function Container(param) { this.member = param; } So, if we construct a new object var myContainer = new Container('abc'); then myContainer.member contains 'abc'. In the prototype This technique is usually used to add public methods. Container.prototype.stamp = function (string) { return this.member + string; } So, we can invoke the method Private.

JS WAT Talk reup. Understand JavaScript’s “this” With Clarity, and Master It. (Also learn all the scenarios when this is most misunderstood.) Prerequisite: A bit of JavaScript.Duration: about 40 minutes. The this keyword in JavaScript confuses new and seasoned JavaScript developers alike. This article aims to elucidate this in its entirety. By the time we make it through this article, this will be one part of JavaScript we never have to worry about again. We use this similar to the way we use pronouns in natural languages like English and French. If we use person.firstName and person.lastName, as in the last example, our code becomes ambiguous. Just like the pronoun “he” is used to refer to the antecedent (antecedent is the noun that a pronoun refers to), the this keyword is similarly used to refer to an object that the function (where this is used) is bound to.

JavaScript’s this Keyword Basics First, know that all functions in JavaScript have properties, just as objects have properties. Ruminate on this basic example illustrating the use of this in JavaScript: Var. The variable statement declares a variable, optionally initializing it to a value. Syntax var varname1 [= value1 [, varname2 [, varname3 ... [, varnameN]]]]; varnameN Variable name. It can be any legal identifier. valueN Initial value of the variable. Description Variable declarations, wherever they occur, are processed before any code is executed. Assigning a value to an undeclared variable implicitly creates it as a global variable (it becomes a property of the global object) when the assignment is executed. 1. Function x() { y = 1; var z = 2;} x(); console.log(y);console.log(z); 2. Console.log(a); console.log('still going var a; console.log(a); console.log('still going 3.

Var a = 1; b = 2; delete this.a;delete this.b; console.log(a, b); Because of these three differences, failure to declare variables will very likely lead to unexpected results. Var hoisting bla = 2var bla;var bla; bla = 2; Examples Declaring and initializing two variables var a = 0, b = 0; var a = "A";var b = a; var a, b = a = "A";