Skip to content

Instantly share code, notes, and snippets.

@xgqfrms-GitHub
Last active July 3, 2020 17:05
Show Gist options
  • Save xgqfrms-GitHub/19479fdadbbc05356aceaf56073bec6d to your computer and use it in GitHub Desktop.
Save xgqfrms-GitHub/19479fdadbbc05356aceaf56073bec6d to your computer and use it in GitHub Desktop.
ecma-262 6.0 class

How To Reading ECMA-262

http://www.ecma-international.org/ecma-262/6.0/#sec-class-definitions

14.5 Class Definitions

Syntax

ClassDeclaration[Yield, Default] :
    class BindingIdentifier[?Yield] ClassTail[?Yield]
    [+Default] class ClassTail[?Yield]
    
ClassExpression[Yield] :
    class BindingIdentifier[?Yield]opt ClassTail[?Yield]
    
ClassTail[Yield] :
    ClassHeritage[?Yield]opt { ClassBody[?Yield]opt }
    
ClassHeritage[Yield] :
    extends LeftHandSideExpression[?Yield]
    
ClassBody[Yield] :
    ClassElementList[?Yield]
    
ClassElementList[Yield] :
    ClassElement[?Yield]
    ClassElementList[?Yield] ClassElement[?Yield]
    
ClassElement[Yield] :
    MethodDefinition[?Yield]
    static MethodDefinition[?Yield]
    ;

NOTE A ClassBody is always strict code.

blogs

https://chadaustin.me/2012/12/javascript-new-operator-ecma-262/

https://stackoverflow.com/questions/2738736/confused-with-ecmascript-language-specification-function-calls-section

http://stackoverflow.com/questions/761905/how-will-ecma-262-ecmascript-5-help-you

https://blog.appdynamics.com/engineering/7-ways-es2015-can-improve-your-javascript-programing/

https://leanpub.com/understandinges6/read

https://lightrains.com/blogs/es6#classes

@xgqfrms-GitHub
Copy link
Author

JavaScript 变量提升(Hoisting)

http://www.dongcoder.com/detail-270846.html

https://zonxin.github.io/post/2015/10/javascript-hoisting

http://www.jianshu.com/p/159b95d3e533

http://www.bbsmax.com/R/B0zqv2QJvL/

Closures

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Closures

闭包是指这样的作用域,它包含有一个函数,这个函数可以调用被这个作用域所封闭的变量、函数或者闭包等内容。
通常我们通过闭包所对应的函数来获得对闭包的访问。

// global  var
var counter = 0;

function add() {
    counter += 1;
    console.log(counter);
}

add();
// 1
add();
// 2
add();
// 3


// local var
function add() {
    var counter = 0;
    // overwrite
    counter += 1;
    console.log(counter);
}

add();
// 1
add();
// 1
add();
// 1

var local-vs-global

@xgqfrms-GitHub
Copy link
Author

闭包

function init() {
  let name = "Mozilla"; 
  // name 是一个被init创建的局部变量
  function displayName() { 
  // displayName() 是一个内部函数,
      alert(name); 
      //  一个闭包使用在父函数中声明的变量
  } 
  displayName();
}
init(); 

let-var already been declared

add()(); === var add = add(); add();

function add() {
    var counter = 0;
    return function () {
        console.log(counter);
        return counter += 1;
    }
}

add()();
// var add = add(); add();

@xgqfrms-GitHub
Copy link
Author

es6 let & emoji

https://github.com/xgqfrms-GitHub/Native-JavaScript/blob/master/es6-emoji.html

https://jsfiddle.net/sybn4h33/3/

You can't comment at this time — your comment contains unicode characters above 0xffff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment