GithubHelp home page GithubHelp logo

joehetfield / you-dont-know-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from getify/you-dont-know-js

1.1K 1.1K 296.0 6.77 MB

A book series on JavaScript. @YDKJS on twitter.

Home Page: http://www.kickstarter.com/projects/getify/you-dont-know-js-book-series

License: Other

JavaScript 87.99% HTML 9.19% CSS 2.82%

you-dont-know-js's Issues

关于this的疑惑

function foo() {
	var a = 2;
	this.bar();
}

function bar() {
	console.log( this.a );
}

foo(); //undefined

这段代码在chrome控制台执行的时候,不会报错,是可以执行的。
但是在node环境中,是直接报错“TypeError: this.bar is not a function”。
请问,这种情况该如何有效的理解?

ES6与未来中第二章语法发现一处疑问。

在“块儿作用于的函数”这个部分有这样一个例子:

if (something) {
function foo() {
console.log( "1" );
}
}
else {
function foo() {
console.log( "2" );
}
}

foo(); // ??

后面的解释“在前ES6环境下,无论something的值是什么foo()都将会打印"2",因为两个函数声明被提升到了块儿的顶端,而且总是第二个有效。”真的是这样吗?我测试了一下,去掉两组花括号(块作用域消失,语义上正好等价于ES5环境),something用true来替换,运行的结果是1.

看了一下英文的原文也是这样,是作者错了还是我的测试方法有误?因为我的英文不好,就不去原版发issues了,在这里求大神指点。

第二章:`this` .... 中关于bind的polyfill有些问题

文章中,bind的polyfill中判断bind返回的方法是否被用作构造函数时用到的方法如下:

this instanceof fNOP && oThis ? this : oThis

私以为,此处不需要再判断oThis是否存在,直接

this instanceof fNOP ? this : oThis

即可。
毕竟bind的第一个参数可以传入null

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.