You might like jsfeatures.in
Includes:
Minimalist examples of ES6 functionalities.
Home Page: http://git.io/es6-paws
You might like jsfeatures.in
Includes:
โ
Was looking for example on promises that was introduced in ES6
function aboutme(){
{
let wife = 1;
var gfs = 10;
}
console.log(wife,gfs); // 1, undefined.
}
Shouldn't that be:
function aboutme(){
{
let wife = 1;
var gfs = 10;
}
console.log(wife,gfs); // undefined, 10
}
as variables with let are block scoped so wife is not visible to console right?
โ
I'm not sure the constructor-like example in arrow.js
from 844241b is correct.
According to @lukehoban's ES6 Features document cited by the Babel team:
arrows share the same lexical
this
as their surrounding code
According to @sebmck in a comment before closing babel/babel#730:
Top level
this
is undefined ES6 modules as they're implicitly strict mode.
Arrow functions inherit the outerthis
.
The practical upshot of which is that your Person
example isn't the constructor you might think it is. Inside the function, this
cannot refer to a constructed object. Instead, this
is undefined
. As Babel transpiles it:
var Person = function (fname, lname, age) {
undefined.fname = fname;
undefined.lname = lname;
undefined.age = age;
undefined.yo = function () {
return "Yo! I'm " + undefined.fname + "!";
}; // `this` reffers to Person.
};
Make Person
an ES6 class or ES5 constructor function, and yo
works as you expect:
// ES6
class Person {
constructor(fname, lname, age) {
this.fname= fname;
this.lname = lname;
this.age = age;
this.yo = () => `Yo! I'm ${this.fname}!`; // `this` refers to Person.
}
}
// ES5
function Person(fname, lname, age) {
this.fname= fname;
this.lname = lname;
this.age = age;
this.yo = () => `Yo! I'm ${this.fname}!`; // `this` refers to Person.
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.