gpt4 book ai didi

javascript - 任何 IDE 中的 Oo javascript 代码补全

转载 作者:搜寻专家 更新时间:2023-11-01 04:26:38 25 4
gpt4 key购买 nike

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

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

最佳答案

您可以使用安装了 Resharper 6 的 WebStorm 或 VisualStudio 之类的东西,它会构建所有对象的所有原型(prototype)的列表,您可以使用它。它不是特别有用,我也不会推荐它。但总比没有好。 .

关于javascript - 任何 IDE 中的 Oo javascript 代码补全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12446896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com