Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在任何IDE中完成Oo javascript代码_Javascript_Oop_Ide_Code Completion - Fatal编程技术网

在任何IDE中完成Oo javascript代码

在任何IDE中完成Oo javascript代码,javascript,oop,ide,code-completion,Javascript,Oop,Ide,Code Completion,你知道有哪种IDE可以自动完成这种代码吗 我这里有一个javascript类生成器: (function() { var core = { bind : function(method, scope) { if (!( method instanceof Function)) throw new TypeError("Function needed as method."); if ( typ

你知道有哪种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;
    };
})(); 
我需要这些示例类的代码完成(写在注释中):

//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中,这些函数正在创建函数实例,它们正在写入这些实例的原型中。这只能通过手动索引我的代码来实现,比如jsdoc,但这还不足以描述继承。所以我需要一个IDE,它至少可以处理js继承,并且我可以为它编写一个插件,自动创建这个索引。(也许插件也可以处理继承,我不知道索引是如何工作的…)


哪个IDE能够做到这一点(以及如何做到)?

您可以在安装了Resharper 6的情况下使用WebStorm或VisualStudio之类的工具,它会生成所有对象的所有原型列表,您可以使用它。。它不是特别有用,我也不推荐它。。但是有些事情总比什么都没有好。

解决方案1:

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

解决方案2:

环顾四周,发现真正的问题是,无论是在Netbeans中,还是在eclipsejsdt和Aptana中,jsdoc3都不完全受支持。我发现唯一支持JSDOC3的IDE是Jetbrains WebStorm,所以我将使用它。(没有测试Visual Studio的Resharper,但它也是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

您希望IDE自动完成什么?显示一个示例..Function.create、ParentClass.extend的返回值和实例。。。像javadoc这样的Ofc对我来说是可以接受的。最好的方法是,我可以覆盖代码完成插件来解释这些特殊功能……JetBrains的IntelliJ是市场上最好的IDE,可以说是现成的。我不确定我是否理解您的需求,但它在JavaScript方面做得很好。嗯,我在顶部有一个特殊的代码,它从给定的对象(在给定/创建的函数的原型中编写)创建JavaScript类。我需要完成该类实例的代码。对于一个常规的代码完成器来说,这有点棘手,但例如netbeans可以通过php从phpdoc读取索引,所以我想可能有一个IDE可以通过类似jsdoc的东西读取代码完成的索引。。。或者有一个IDE,我可以为这个javascirpt代码之王编写一个索引读取器插件…大约一个月前尝试过phpStorm,但它的php代码着色效果比netBeans差,而且我在自动完成方面也有问题。。。现在下载webStorm,我会尝试一下。是的,但我不会手动编写原型,比如:MyClass.prototype.doSomething=function(){console.log(“某物”);}我编写的代码是:MyClass=function.create({doSomething:function(){console.log(“某物”);});那是我的问题。。。IDE必须以某种方式理解此代码写入到原型中,这是最困难的部分…很接近,但还不够接近。。。(顺便说一句,我投了你一票。)