2012-09-16 6 views
5

この種のコードを自動完成できるIDEはありますか?すべてのIDEでjavascriptコードが完了

私はここにjavascriptのクラスの発電機を持っている:

(function() { 
    var core = { 
     bind : function(method, scope) { 
      if (!(method instanceof Function)) 
       throw new TypeError("Function needed as method."); 
      if (typeof (scope) != "object") 
       throw new TypeError("Object needed as scope."); 
      return function() { 
       return method.apply(scope, arguments); 
      }; 
     }, 
     require : function(source) { 
      if (typeof (source) != "object" || !source) 
       throw new TypeError("Object needed as source."); 
      for (var property in source) 
       if (source.hasOwnProperty(property) && !this.prototype.hasOwnProperty(property)) 
        this.prototype[property] = source[property]; 
     }, 
     override : function(source) { 
      if (typeof (source) != "object" || !source) 
       throw new TypeError("Object needed as source."); 
      for (var property in source) 
       if (source.hasOwnProperty(property)) 
        this.prototype[property] = source[property]; 
     }, 
     extend : function(source) { 
      var superClass = this; 
      var newClass = source.hasOwnProperty("constructor") ? source.constructor : function() { 
       superClass.apply(this, arguments); 
      }; 
      newClass.superClass = superClass; 

      var superClone = function() { 
      }; 
      superClone.prototype = superClass.prototype; 
      newClass.prototype = new superClone(); 
      newClass.prototype.constructor = newClass; 

      if (source) 
       newClass.override(source); 
      return newClass; 
     } 
    }; 

    core.require.call(Function, core); 

    Function.create = function (source){ 
     var newClass = source.hasOwnProperty("constructor") ? source.constructor : function() {}; 
     newClass.override(source); 
     return newClass; 
    }; 
})(); 

私はこれらの例のクラスのために(コメントで書いた)コード補完が必要になります。

//Function.prototype: bind, require, override, extend 
//Function.create 

var A = Function.create({ //offer Function.[create] 
    test: function(){ 
     console.log("a"); 
    } 
}); 

//A is a Function instance 
//A.prototype: test 

var B = A.extend({ //offer A.[extend] 
    test: function(){ 
     console.log("b"); 
    }, 
    test2: function(){ 
     console.log("b2"); 
    } 
}); 

//B is a Function instance 
//B.prototype inherits from A.prototype 
//B.prototype.test overrides A.prototype.test 

var F = Function.create({ //offer Function.[create] 
    getA: function(){ 
     return new A(); 
    }, 
    getB: function(){ 
     return new B(); 
    } 
}); 
//F is a Function instance 
//F.prototype getA, getB returns A and B instances 

var f = new F(); //offer [F] 
//f inherits from F.prototype 
var a = f.getA(); //offer f.[getA] 
//a inherits from A.prototype 
var b = f.getB(); //offer f.[getB] 
//b inhertis from B.prototype 

a.test(); //offer a.[test] 
b.test(); //offer b.[test] 
b.test2(); //offer b.[test2] 

だから私はIDEは何とか知らせなければなりません、これらの関数はFunction.prototypeに存在し、これらの関数はFunctionインスタンスを作成しており、それらのインスタンスのプロトタイプに書き込んでいます。これはjsdocのように私のコードを手動で索引付けするだけで可能ですが、継承などを説明するには不十分です。だから私は少なくともjsの継承を処理することができるIDEが必要であり、このためにこのインデックスを自動的に作成するプラグインを書くことができます。 (プラグインでも継承を処理できるかもしれませんが、私はそのインデックス作成がどのように正確に動作するかわかりません...)

どのようなIDEが可能ですか?

+0

あなたはIDEの自動補完するために何をしたいですか?例を示してください.. – Baz1nga

+0

Function.create、ParentClass.extend、およびインスタンスの戻り値... Ofcのようなjavadocは私には受け入れられます。最高ののは、これらの特別な機能を解釈するためのコード補完プラグインを無効にすることができる場合です。 – inf3rno

+1

JetBrainsのIntelliJは、市場で最高のIDEです。私はあなたの要件を理解しているかどうかはわかりませんが、JavaScriptを使って美しい仕事をしています。 – duffymo

答えて

2

解決策1:

私は、EclipseでJavaScriptのインデクサがWebツールプラットフォーム/ Javascriptの開発ツールの一部であることがわかりました。 The source code is here.開発者は、InferEngineは簡単に拡張可能であると書いていますので、Eclipseプラグインを作成できます。 その場合、this blogは本当に本当に本当に便利です。 JSDTを拡張する方法については素晴らしい記事があり、JSDT開発者も手助けすることができます。残念ながら、別の解決策がある場合、私はそのようなことを作る時間があまりありません。

ソリューション2:

は周りを見て、本当の問題は、そのJSDocの3は、NetBeansで、またEclipseのJSDTとAptanaの中にも完全にサポートされていないことが判明しました。 JSDOC 3でサポートされている唯一のIDEはJetbrains WebStormですので、私はそれを使用します。 (Visual StudioのためReSharperのをテストするが、それはどちらかJetBrainsの製品ですので、それはおそらく、あまりにも機能しませんでした。)

元の例をJSDocの3とwebstormに:

/** @class*/ 
var A = Function.create(//offer Function.[create] -> OK! 
/** @lends A.prototype*/ 
{ 
    test: function(){ 
     console.log("a"); 
    }, 
    testA: function(){ 
     console.log("a2"); 
    } 
}); 

/** @class*/ 
/** @extends A*/ 
var B = A.extend(//offer A.[extend] -> OK! 
/** @lends B.prototype*/ 
{ 
    test: function(){ 
     console.log("b"); 
    }, 
    testB: function(){ 
     console.log("b2"); 
    } 
}); 

/** @class*/ 
var F = Function.create(//offer Function.[create] -> OK! 
/** @lends F.prototype*/ 
{ 
    /** @returns A*/ 
    getA: function(){ 
     return new A(); 
    }, 
    /** @returns B*/ 
    getB: function(){ 
     return new B(); 
    } 
}); 

var f = new F(); 
f.getA().test(); //offer f.[getA], offer f.getA().[test] -> OK 
f.getA().testA(); //offer f.[getA], offer f.getA().[testA] -> OK 
f.getB().test(); //offer f.[getB], offer f.getB().[test] -> OK 
f.getB().testA(); //offer f.[getB], offer f.getB().[testA] -> OK 
f.getB().testB(); //offer f.[getB], offer f.getB().[testB] -> OK 
1

Resharper 6がインストールされたWebStormやVisualStudioのようなものを使うことができます。すべてのオブジェクトのプロトタイプのリストを作成し、それを使用することもできます。特に有用ではありません。 ..

+0

ええ、私は手動でプロトタイプのように書くことはありません: MyClass.prototype.doSomething = function(){console.log( "something"); } 私はこのようなコードを書いています: MyClass = Function.create({ doSomething:function(){console.log( "something");} }); それは私の問題です... IDEは何とかこのコードがプロトタイプに書き込むことを理解しなければなりません。それは難しい部分です... – inf3rno

+0

近いが、十分ではなかった...(私はあなたに投票を与えた。 – inf3rno

関連する問題