サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
2024年ランキング
javascriptweblog.wordpress.com
Lets start with a short quiz. What is alerted in each case?: Question 1: function foo(){ function bar() { return 3; } return bar(); function bar() { return 8; } } alert(foo()); Question 2: function foo(){ var bar = function() { return 3; }; return bar(); var bar = function() { return 8; }; } alert(foo()); Question 3: alert(foo()); function foo(){ var bar = function() { return 3; }; return bar(); v
The next JavaScript specification is moving towards completion. TC39, the technical committee charged with creating ES.next (also known as ES Harmony, and sometimes ES 6) has already tentatively approved a number of proposals and there are a bunch more straw men awaiting approval. TC39 includes some of the finest minds in JavaScript (not least, Brendan Eich himself) but as Jeremy Ashkenas famously
It’s official! We’re getting a new function syntax! The TC39 group (the panel charged with delivering ES 6) has reached consensus on an abbreviated syntax for JavaScript function expressions. Its popularly known as the fat arrow syntax, and is based on a similar construct found in CoffeeScript. Make no mistake, I’m delighted that we will finally have an alternative to the unnecessary clunkiness an
Most built-in JavaScript types are constructors whose prototypes contain the methods and other properties that define their default behavior: //(results will vary by browser) Object.getOwnPropertyNames(Function.prototype) //["bind", "arguments", "toString", "length", "call", "name", "apply", "caller", "constructor"] You can’t delete or replace a native prototype, but you can edit the values of its
You may not know it but, in JavaScript, whenever you interact with string, number or boolean primitives you enter a hidden world of object shadows and coercion. So dust off your Sherlock Holmes outfit and read on… The basics Objects are aggregations of properties. A property can reference an object or a primitive. Primitives are values, they have no properties. In JavaScript there are 5 primitive
What’s wrong with typeof? The most glaring issue is that typeof null returns “object”. It’s simply a mistake. There’s talk of fixing it in the next version of the ECMAScript specification, although this would undoubtedly introduce backwards compatibility issues. var a; typeof a; //"undefined" typeof b; //"undefined" alert(a); //undefined alert(b); //ReferenceError Other than that, typeof is just n
Here’s a tiny util that you can save as a bookmarklet and use to crawl the JavaScript object model of any web site. Waldo (thanks to @shinypb for the name!) lets you find and inspect instances by name, type or value, and it can be easily customized to add additional tests. It runs in the console on Chrome, Firefox, Safari and IE>8. It's sourced on github. Feel free to fork it if you want to add mo
(In Portugese) The JavaScript this keyword is ubiquitous yet misconceptions abound. What you need to know Every execution context has an associated ThisBinding whose lifespan is equal to that of the execution context and whose value is constant. There are three types of execution context: global, function and evaluation. Here’s a tabular summary followed by a little more detail, and some examples:
(Russian, Japanese) In this article I’ll explore JavaScript mixins in detail, and introduce a less conventional, but to my mind more natural mixin strategy that I hope you’ll find useful. I’ll finish up with a profiler matrix summarizing the performance impact of each technique. [A big Thank You to the brilliant @kitcambridge for reviewing and improving the code on which this blog is based!] Re-us
The fifth edition of the ECMAScript specification introduced Strict Mode. Strict Mode imposes a layer of constraint on JavaScript – intended to protect you from the more perilous aspects of the language. While researching this article I wrote 38 tests covering all the Strict Mode rules as defined in the ES5 specification. You can see how your favorite browser shapes up by clicking here. The code f
(на русском, 日本) Let’s begin with a funny tweet: The ‘c’ at the end is for the lowly comma operator. Last in the line of operator precedence and rarely documented, the comma operator hides its light under a bushel. It may not be a JavaScript heavy-hitter but I like it anyway. Its simple, elegant and you should make it your friend. So, here we go – more than you’ll ever need to know about JavaScrip
You don’t have to be a JavaScript novice to get confused by this… if ([0]) { console.log([0] == true); //false console.log(!![0]); //true } or this… if ("potato") { console.log("potato" == false); //false console.log("potato" == true); //false } The good news is that there is a standard and all browsers follow it. Some authors will tell you to fear coercion and and code against it. I hope to persu
Global variables should be reserved for objects that have system-wide relevance and they should be named to avoid ambiguity and minimize the risk of naming collisions. In practice this means you should avoid creating global objects unless they are absolutely necessary. But, hey, you already knew all that….. So what do you do about it? Conventional wisdom tells us that the best global abatement str
Most browsers are coalescing around a consistent API for defining JavaScript Getters and Setters. I’m not entirely comfortable with custom getters and setters – JavaScript’s clean syntax is now a little murkier, and we have a new pitfall to avoid when iterating and cloning object properties, not to mention a significant risk of involuntary recursion – but still I’ll admit they have their uses. I’m
In JavaScript, a closure is a function to which the variables of the surrounding context are bound by reference. function getMeAClosure() { var canYouSeeMe = "here I am"; return (function theClosure() { return {canYouSeeIt: canYouSeeMe ? "yes!": "no"}; }); } var closure = getMeAClosure(); closure().canYouSeeIt; //"yes!" Every JavaScript function forms a closure on creation. In a moment I’ll explai
(versión abreviada en español) If you think the introduction of Array.prototype.forEach and friends will send the for-loop the way of the dodo, think again. There’s life in the old dog yet. The for-loop is often seen as something of a one trick pony, most suited to the classic form of list iteration: for (var i=0; i<arr.length; i++) { //do something to each member } but with the wealth of higher o
(en Español, русском, 中文) JavaScript’s prototype object generates confusion wherever it goes. Seasoned JavaScript professionals, even authors frequently exhibit a limited understanding of the concept. I believe a lot of the trouble stems from our earliest encounters with prototypes, which almost always relate to new, constructor and the very misleading prototype property attached to functions. In
Behold, the new hotness! The shapely Arrow Function has driven away the irksome function keyword and (by virtue of lexical this scoping) bought joy to many a JavaScript programmer. Yet, as the following account relates, even the best tools should be used with discretion. Continue reading “Of Classes and Arrow Functions (a cautionary tale)” → I wrote a book called If Hemingway Wrote JavaScript in w
The native JavaScript function indexOf, applied to a String, returns the index of the first occurrence of a specified value. Useful as it is, I often find myself wishing for a variant method that will return the index after the occurrence so that I can pass the result to a slice call and return everything after a given character. With this in mind, I created a method called express (as in expressi
このページを最初にブックマークしてみませんか?
『JavaScript, JavaScript...』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く