简体   繁体   中英

Does NetBeans recognize JavaScript prototypal inheritance?

Does NetBeans recognize JavaScript prototypal inheritance? To me it seems that it does not:

Code:

function A() {} 
A.prototype.doSomething = function () {} 

function B() {} 
B.prototype = new A(); 

var test = new B(); 
test.

after typing the dot and pressing ctrl+space I do not see doSomething()-method, but everything in B is covered though (in this example nothing).

Netbeans, being a Java IDE, does, indeed, not function fully with JS,

prototype inheritance being one of these things.

In fairness - I can't see this being a common or critical issue.

Yes it does (at least 7.0 beta2)! You have to use prototype.js syntax for extending classes, but you can hide it in if (false) conditional, so you don't need the prototype.js actually...

Your example will look like:

function A() {} 
A.prototype.doSomething = function () {} 

function B() {} 
B.prototype = new A(); 
// here is the magic trick
if (false) var B = Class.create(A, {});

var test = new B(); 

You can use any of these:

  • var B = Class.create(A, {})
  • var B = Object.extend(new A(), {});

As a side note, the whole DOM is built around class-like inheritance, so it's rather important for IDEs to properly support it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM