在任何IDE中完成oo javascript代码

inf*_*rno 5 javascript ide oop code-completion

你知道任何可以自动完成这种代码的IDE吗?

我这里有一个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;
    };
})(); 
Run Code Online (Sandbox Code Playgroud)

我需要这些示例类的代码完成(在注释中写):

//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]
Run Code Online (Sandbox Code Playgroud)

所以我必须让IDE以某种方式知道,这些函数存在于Function.prototype中,并且这些函数正在创建Function实例,并且它们正在写入这些实例的原型.这只能通过我的代码的手动索引来实现,比如jsdoc,但这还不足以描述继承.所以我需要一个可以处理至少js继承的IDE,我可以编写一个自动创建索引的插件.(也许插件也可以处理继承,我不知道索引是如何工作的......)

哪个IDE能够(以及如何)?

inf*_*rno 2

解决方案1:

我发现在 Eclipse 中,javascript 索引器是 Web 工具平台/Javascript 开发工具的一部分。源代码在这里。开发人员写道,InferEngine 易于扩展,因此您可以编写 eclipse 插件。在这种情况下,这个博客真的非常非常有用。它有关于如何扩展 JSDT 的精彩文章,JSDT 开发人员也可以提供帮助。不幸的是,如果有其他解决方案,我没有太多时间来创建这样的东西。

解决方案2:

环顾四周,发现真正的问题是,JSDOC 3 在 Netbeans、Eclipse JSDT 和 Aptana 中都不完全支持。我发现的唯一支持 JSDOC 3 的 IDE 是 Jetbrains WebStorm,所以我将使用它。(没有测试 Resharper for Visual Studio,但它也是 JetBrains 产品,所以它也可能有效。)

webstorm 中 jsdoc 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
Run Code Online (Sandbox Code Playgroud)