francoisnature
Contributor
Contributor

How do extends work in VRO ?

Hi,

 

 

I'm a beginner with VRO and javascript and am trying to get an understanding.

I found some VRO code that had  for example : controller instanceof VcVirtualBusLogicController

I learnt about Javascript object prototypes and am trying now to understand how VRO works with chain of prototypes.

 

 

I see for example in the API VRO book that the class  VcVirtualBusLogicController extends the class VcVirtualSCSIController that extends VcVirtualController and so on .

However when I go up the prototype chain in the code, it doesn't match the extends as explained in the API.

 

 

In below Example:

Here I would have expected that proto2  refers to parent class VcVirtualSCSIController  and not directly the root Object.

I'm not sure to understand why there is no proto link between the class objects in VRO or vCenter API.

How do extends work in VRO ?

 

<script>
var devices = vm.config.hardware.device;
for each (var controller in devices) {
  var is_scsi = controller instanceof VcVirtualBusLogicController || controller instanceof VcVirtualLsiLogicController || controller instanceof VcParaVirtualSCSIController || controller instanceof VcVirtualLsiLogicSASController;
  
  if (!is_scsi) {continue;}

  var proto = controller.__proto__;
  var proto2 = proto.__proto__;
  var construct = controller.constructor;

  System.log(" controller is "+ controller );
  System.log(" proto is "+proto);
  System.log(" proto2 is "+proto2);
  System.log(" construct is "+construct);
}
2021-08-03 16:49:52.127 +02:00info controller is DynamicWrapper (Instance) : [VcParaVirtualSCSIController]-[class com.vmware.o11n.plugin.vsphere_gen.ParaVirtualSCSIController_Wrapper] -- VALUE
...
16:49:52.128 +02:00info proto is DynamicWrapper (Class) : [VcParaVirtualSCSIController]-[class com.vmware.o11n.plugin.vsphere_gen.ParaVirtualSCSIController_Wrapper] -- VALUE : null
2021-08-03 16:49:52.129 +02:00info proto2 is [object Object]
2021-08-03 16:49:52.132 +02:00info construct is function Object() { [native code for Object.Object, arity=1] }

</script>

 

0 Kudos
1 Reply
francoisnature
Contributor
Contributor

I was thinking: 

javascript SDK on VRO side just instanciates the class it needs. And the inheritance really happens only on vCenter side. Is that correct ?

0 Kudos