2014-10-31 28 views
0

代碼就是從這裏開始:https://github.com/facebook/flux/blob/c62ad1e76f00b880df8e55b00aa9296b627e0ab7/src/Dispatcher.js#L111爲什麼Flux可以在Javascript中使用「class」?

class Dispatcher { 
    constructor() { 
    this._callbacks = {}; 
    this._isPending = {}; 
... 

什麼樣的語法在這裏它使用?據我所知,「class」是Javascript 2.0中的一項重要工作,而許多瀏覽器都不支持它。爲什麼在這裏使用它?它工作嗎?

+1

「Class」不是ECMAScript [*關鍵詞*](http://ecma-international.org/ecma-262/5.1/#sec-7.6.1.1),它是[*未來的保留字* ](http://ecma-international.org/ecma-262/5.1/#sec-7.6.1.2)。 ;-)由於ECMA-262 ed 6是一個可能的未來,它有[*類*](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-class-definitions)。至少目前來說。 – RobG 2014-10-31 06:23:17

回答

0

觀察助熔劑Gulp文件可以解答您的問題。

gulp.task('lib', function() { 
    return gulp.src('src/*.js') 
      .pipe(gReact({harmony: true})) 
      .pipe(gReplace(/__DEV__/g, 'false')) 
      .pipe(gulp.dest('lib')); 

}); 

這裏,gReact代表var gReact = require('gulp-react')有趣的事實,有在SORCE文件:

在故宮這裏是一個缺少分號在https://www.npmjs.org/package/gulp-react

react(options) 

options.harmony 

Type: boolean 
Default: false 

Enable harmony features for JSX. 

,所以我想吞掉會做出一些構建時,從ES.next代碼轉換爲ES.current。

+0

正確!真正的工作是由這位訪問者完成的:https://github.com/facebook/jstransform/blob/master/visitors/es6-class-visitors.js – 2014-10-31 11:11:44

相關問題