簡體   English   中英

領先的Underscore在es6課程中出現了錯誤

[英]Leading Underscore transpiled wrong with es6 classes

我正在經歷一個非常奇怪的行為,甚至無法說出應該歸咎於哪個包。 我的設置:RequireJS項目與JSXTransformer和jsx! 插件我有這樣的es6類:

define([
    'react'
], function(
    React
) {

    class MyComponent extends React.Component {

        myMethod() {
            otherObject.someMethod()._privateProp; // Yes, we need this accessing and have no influence on it
        }

    }

    return MyComponent;

});

運行r.js后生成的包中的轉換輸出為:

define('jsx!project/components/InputOutput',[
    'react'
], function(
    React
) {

    var ____Class8=React.Component;for(var ____Class8____Key in ____Class8){if(____Class8.hasOwnProperty(____Class8____Key)){MyComponent[____Class8____Key]=____Class8[____Class8____Key];}}var ____SuperProtoOf____Class8=____Class8===null?null:____Class8.prototype;MyComponent.prototype=Object.create(____SuperProtoOf____Class8);MyComponent.prototype.constructor=MyComponent;MyComponent.__superConstructor__=____Class8;function MyComponent(){"use strict";if(____Class8!==null){____Class8.apply(this,arguments);}}

        MyComponent.prototype.myMethod=function() {"use strict";
            otherObject.someMethod().$MyComponent_privateProp;
        };



    return MyComponent;

});

注意otherObject.someMethod().$MyComponent_privateProp; 寫在那里。 這顯然會中斷,因為它不是MyComponent實例的屬性。

/** @preventMunge */添加到文件的頂部。 看到這個GitHub問題

是的,對不起,這是一個非標准的fb-ism。 現在你可以解決這個問題,並通過將/** @preventMunge */放在文件的頂部來關閉此功能 - 但這也是一個非常大的fb-ism。 我們應該(a)將其轉換為轉換選項(而不是直接docblock指令)和(b)使其選擇加入而不是選擇退出(因為它是非標准的)。

對於上下文:我們在每個模塊的基礎上挖掘所有欠前綴對象屬性,部分原因是我們的欠前綴約定適用於對象和類。 此外,即使我們想松懈的對象VS類的區別,這是不可能告訴(一般情況下),如果一個屬性是一個參考this ,因為別名變量可以出現(即var self = this; self._stuff;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM