2012-09-16 13 views
5

में ओओ जावास्क्रिप्ट कोड पूर्णता क्या आप किसी भी आईडीई को जानते हैं जो इस तरह के कोड को स्वत: पूर्ण कर सकता है?किसी भी आईडीई

मैं यहाँ एक जावास्क्रिप्ट वर्ग जनरेटर है:

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

तो मैं आईडीई किसी भी तरह पता है चाहिए, कि ये फ़ंक्शंस फ़ंक्शन.प्रोटोटाइप में मौजूद हैं, और ये फ़ंक्शन फ़ंक्शन इंस्टेंस बना रहे हैं और वे उन उदाहरणों के प्रोटोटाइप में लिख रहे हैं। यह केवल मेरे कोड की मैन्युअल इंडेक्सिंग के साथ ही संभव है, जैसे jsdoc, लेकिन उदाहरण विरासत के लिए वर्णन करने के लिए पर्याप्त नहीं है। इसलिए मुझे एक आईडीई की आवश्यकता है जो कम से कम जेएस विरासत को संभाल सके, और जिसके लिए मैं एक प्लगइन लिख सकता हूं जो स्वचालित रूप से इस इंडेक्सिंग को बनाता है। (शायद प्लगइन विरासत को भी संभाल सकता है, मुझे नहीं पता कि यह इंडेक्सिंग वास्तव में कैसे काम करता है ...)

कौन सा आईडीई उस (और कैसे) में सक्षम है?

+0

क्या आप आईडीई स्वत: पूर्ण करना चाहते हैं: webstorm में jsdoc 3 के साथ मूल उदाहरण (Resharper दृश्य स्टूडियो के लिए परीक्षण नहीं किया, लेकिन यह या तो जेटब्रेन्स उत्पाद है, तो यह संभवतः भी काम करता है।)

? एक उदाहरण दिखाएं .. – Baz1nga

+0

Function.create, ParentClass.extend, और उदाहरणों के वापसी मान ... javadoc की तरह कुछ भी मेरे लिए स्वीकार्य है। सबसे अच्छा होगा अगर मैं इन विशेष कार्यों की व्याख्या करने के लिए कोड पूर्णता प्लगइन को ओवरराइड कर सकता हूं ... – inf3rno

+1

जेटब्रेन से इंटेलिजे बाजार पर हाथों का सबसे अच्छा आईडीई है। मुझे यकीन नहीं है कि मैं आपकी आवश्यकता को समझता हूं, लेकिन यह जावास्क्रिप्ट के साथ एक सुंदर काम करता है। – duffymo

उत्तर

2

समाधान 1:

मैंने पाया कि ग्रहण में जावास्क्रिप्ट इंडेक्सर वेब उपकरण मंच/javascript विकास उपकरण का एक हिस्सा है। The source code is here. डेवलपर्स ने लिखा था कि इनफेरइंजिन आसान विस्तार योग्य है, इसलिए आप एक ग्रहण प्लगइन लिख सकते हैं। उस मामले में this blog वास्तव में वास्तव में उपयोगी है। इसमें महान लेख हैं जेएसडीटी का विस्तार कैसे करें, और जेएसडीटी डेवलपर्स भी मदद कर सकते हैं। दुर्भाग्य से यदि कोई दूसरा समाधान है तो ऐसी चीज बनाने के लिए मेरे पास अधिक समय नहीं है।

समाधान 2:

चारों ओर देख और पाया कि वास्तविक समस्या है, कि JSDOC 3 पूरी तरह से समर्थित नहीं है न Netbeans में, और न ही ग्रहण JSDT और Aptana में था। जेएसडीओसी 3 समर्थन के साथ मैंने पाया एकमात्र आईडीई जेटब्रेन वेबस्टॉर्म है, इसलिए मैं इसका उपयोग करूंगा।

/** @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

आप वेबस्टॉर्म या विजुअलस्टूडियो जैसे रिसर्चर 6 के साथ कुछ उपयोग कर सकते हैं और यह सभी ऑब्जेक्ट्स के सभी प्रोटोटाइपों की एक सूची बनाता है और आप इसका उपयोग कर सकते हैं .. यह विशेष रूप से उपयोगी नहीं है और न ही मैं इसकी अनुशंसा करता हूं .. लेकिन कुछ भी नहीं ..

+0

हाँ, लेकिन मैं मैन्युअल रूप से प्रोटोटाइप में लिखता हूं जैसे: MyClass.prototype.doSomething = function() {console.log ("कुछ"); } मैं इस तरह कोड लिखता हूं: MyClass = Function.create ({ doSomething: function() {console.log ("कुछ");} }); यह मेरी समस्या है ... आईडीई को किसी भी तरह समझना चाहिए कि यह कोड प्रोटोटाइप में लिखता है, और यह कठिन हिस्सा है ... – inf3rno

+0

करीब था, लेकिन पर्याप्त नहीं था ... (बीटीडब्ल्यू मैंने आपको वोट दिया था।) – inf3rno