background preloader

Web_development

Facebook Twitter

JavaScript’s “this”: how it works, where it can trip you up. In JavaScript, the special variable this is relatively complicated, because it is available everywhere, not just in object-oriented settings.

JavaScript’s “this”: how it works, where it can trip you up

This blog post explains how this works and where it can cause problems, concluding with best practices. To understand this, it is best to partition the locations where it can be used into three categories: In functions: this is an extra, often implicit, parameter. Outside functions (in the top-level scope): this refers to the global object in browsers and to a module’s exports in Node.js. In a string passed to eval(): eval() either picks up the current value of this or sets it to the global object, depending on whether it is called directly or indirectly.

This in functions this in real functions function func(arg1, arg2) { console.log(this); console.log(arg1); console.log(arg2); } func.call('a', 'b', 'c'); func.apply('a', ['b', 'c']); this in constructors Functions become constructors if you invoke them via the new operator. Understanding the four layers of JavaScript OOP. JavaScript OOP is baffling: on one hand, there is a simple core, on the other hand, there are some really weird things going on.

Understanding the four layers of JavaScript OOP

I’ve been pondering for a long time how to explain it well and I think the best way to do so is via four layers: single objects, prototype chains, constructors, constructor inheritance. The first two layers are JavaScript’s simple OOP core, layers 3 and 4 are where the complications start. I’ve explained the four OOP layers in an O’Reilly webcast: Video on YouTube (starts later to avoid duplicated content at the beginning)SlidesFull webcast (requires Flash, but the audience’s comments in the chat are interesting) Additional material: “In defense of JavaScript’s constructors” explains my – conservative – recommendation of constructors“JavaScript’s ‘this’: how it works, where it can trip you up”Chapter “Objects and Inheritance” in the online version of “Speaking JavaScript”

7 Principles of Rich Web Applications. This is a writeup based on a presentation I gave at BrazilJS in August 2014.

7 Principles of Rich Web Applications

It builds on some of the ideas I’ve been blogging about recently related mostly to UX and performance. I want to introduce 7 actionable principles for websites that want to make use of JavaScript to control their UI. They are the result of my experience as a web developer, but also as a long-time user of the WWW. JavaScript has undeniably become an indispensable tool for frontend developers. Its usage is now expanding into other areas like servers and microcontrollers. Yet a lot of questions on its precise role and usage on the web remain a mystery, even to many framework and library authors. Should JavaScript be used to replace browser functions like history, navigation and page rendering? What follows is my attempt to answer these. . # 1. Tl;DR: Server rendering is not about SEO, it’s about performance. HTML5 Please - Use the new and shiny responsibly.

Understanding “Prototypes” in JavaScript. For the purposes of this post, I will be talking about JavaScript objects using syntax defined in ECMAScript 5.1.

Understanding “Prototypes” in JavaScript

The basic semantics existed in Edition 3, but they were not well exposed. In JavaScript, objects are pairs of keys and values (in Ruby, this structure is called a Hash; in Python, it's called a dictionary). For example, if I wanted to describe my name, I could have an object with two keys: firstName would point to "Yehuda" and lastName would point to "Katz". Keys in a JavaScript object are Strings.

To create the simplest new object in JavaScript, you can use Object.create: var person = Object.create(null); Why didn't we just use var person = {};? Person['name'] If the String is a valid identifier[1], you can use the dot form: person.name [1] in general, an identifier starts with a unicode letter, $, _, followed by any of the starting characters or numbers. So now you have an empty object. Obviously, a property has a name and a value. Obviously, this is extremely verbose. Resources. Edit fiddle. Tag "Web Design" on Smashing Magazine.

As one of the top designers on Dribbble, Jan Martin attracts many followers with his visual design skills.

Tag "Web Design" on Smashing Magazine

Unlike many designers, Jan is incredibly humble about what he has achieved. “Stop following what the visionary designers think,” he says. “There is no wrong or right way. We need to create our own things and always design with our heart.” Jan grew up in the small city of Brandenburg, about 70 kilometers south of Berlin. Geek to Live: How to set up a personal home web server.

Php_mysql

CS75.tv. p4. Facebook api. Login - Can I use the facebook credentials to for users to access my site. Web services. Javascript. Css.