2012-09-16 13 views
5

Conosci qualche IDE che può completare automaticamente questo tipo di codice?Oo completamento del codice javascript in qualsiasi ID

Ho un generatore di classe javascript qui:

(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; 
    }; 
})(); 

ho bisogno di completamento del codice (scritto nei commenti) per queste classi di esempio:

//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] 

Quindi devo lasciare l'IDE in qualche modo sa, che queste funzioni siano presenti nel Function.prototype e queste funzioni stanno creando istanze di funzione e stanno scrivendo nel prototipo di tali istanze. Questo è possibile solo con l'indicizzazione manuale del mio codice, come jsdoc, ma questo non è sufficiente per descrivere ad esempio l'ereditarietà. Quindi ho bisogno di un IDE che possa gestire almeno l'ereditarietà di js, e per il quale posso scrivere un plugin che crei automaticamente questa indicizzazione. (Forse il plugin può gestire anche l'ereditarietà, non so come funziona esattamente l'indicizzazione ...)

Quale IDE è in grado (e come)?

+0

cosa vuoi l'IDE per completare automaticamente ? mostra un esempio .. – Baz1nga

+0

I valori di ritorno di Function.create, ParentClass.extend e le istanze ... Ofc qualcosa come javadoc è accettabile per me. Il meglio sarebbe se potessi scavalcare il plugin di completamento del codice per interpretare queste funzioni speciali ... – inf3rno

+1

IntelliJ di JetBrains è il miglior IDE sul mercato, a mani basse. Non sono sicuro di aver compreso le tue esigenze, ma fa un bel lavoro con JavaScript. – duffymo

risposta

2

soluzione 1:

ho scoperto che in Eclipse l'indicizzatore javascript è una parte del Web Tools Platform/Strumenti di sviluppo Javascript. The source code is here. Gli sviluppatori hanno scritto che InferEngine è facilmente estensibile, quindi puoi scrivere un plug-in di eclissi. In tal caso, this blog è davvero molto utile. Ha ottimi articoli su come estendere JSDT e anche gli sviluppatori JSDT possono aiutarti. Purtroppo non ho molto tempo per creare una cosa del genere se c'è un'altra soluzione.

Soluzione 2:

stava guardando intorno e ha scoperto che il vero problema è, che JSDOC 3 non è supportato completamente né in Netbeans, nè in Eclipse JSDT e Aptana. L'unico IDE che ho trovato con il supporto JSDOC 3 è Jetbrains WebStorm, quindi lo userò. (Non testare l'ReSharper per Visual Studio, ma è prodotto JetBrains o, in modo che forse funziona anche.)

L'esempio originale con jsdoc 3 in 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

È possibile utilizzare qualcosa come WebStorm o VisualStudio con Resharper 6 installato e crea un elenco di tutti i prototipi di tutti gli oggetti ed è possibile utilizzarlo .. non è particolarmente utile né lo consiglierei .. Ma qualcosa di meglio di niente ..

+0

Sì, ma non scrivo manualmente nei prototipi come: MyClass.prototype.doSomething = function() {console.log ("qualcosa"); } Scrivo codice come questo: MyClass = Function.create ({ doSomething: function() {console.log ("qualcosa");} }); Questo è il mio problema ... L'IDE deve in qualche modo capire che questo codice scrive nel prototipo, e questa è la parte difficile ... – inf3rno

+0

Era vicino, ma non abbastanza vicino ... (A proposito ti ho dato una votazione.) – inf3rno

Problemi correlati