Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7783531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:51:58+00:00 2026-06-01T19:51:58+00:00

I know I can call top-level functions defined in JS from VBScript , and

  • 0

I know I can call top-level functions defined in JS from VBScript, and vice versa, like this:

<%@ language="Chakra" %>

<script language='JavaScript' runat='server'>
  function jsFunction1() {
      for (var i=0;i<10;i++) Response.Write(i+"<br>");
      vbFunction2();
  }
</script>

<script language='VBScript' runat='server'>
  Sub vbFunction1 ()
      Response.Write("VB Hello <br/>" & VbCrLf)
      jsFunction1()
  End Sub
  Sub vbFunction2 ()
      Response.Write("VB Goodbye <br/>" & VbCrLf)
  End Sub
</script>


<script language="JavaScript" runat="server">
  vbFunction1();
</script>

I can also include JS into VBScript modules, like this:

<%@ language="VBScript" %>

<script language="Javascript" runat="server" src="includedModule.js"></script>

<script language="VBScript" runat="server">

    ....
</script>

…and the functions defined in the includedModule.js are available in the VBScript.

But suppose I have a Javascript class defined using prototypal OO, like this:

(function() {

  MyObj = function() {
    this.foo = ...
    ...
  };

  MyObj.prototype.method1 = function() { .. };
  MyObj.prototype.method2 = function() { .. };
}());

How can I use that object (aka type, or class) from VBScript?

The vanilla approach…

Dim foo
Set foo = New MyObj

…does not work.

Neither does

Dim foo
foo = MyObj()

…because apparently this is not defined when the JS function is invoked
from VBScript. Or something.

So how can I do it?

The reason this is valuable: there are OO libraries available in Javascript, that would be interesting to use from VBScript.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:52:00+00:00Added an answer on June 1, 2026 at 7:52 pm

    I don’t know how to avoid the problem that VBScript cannot directly call a Javascript “constructor” function. The way I dealt with it was to simply define a shim: a top-level function in Javascript that invokes the constructor from within Javascript and returns the reference.

    So:

    <script language='javascript' runat='server'>(function() {  
      MyObj = function() {  
        this.foo = ...  
        ...  
      };  
    
      MyObj.prototype.method1 = function() { .. };  
      MyObj.prototype.method2 = function() { .. };  
    
      // define a shim that is accessible to vbscript
      Shim = {construct: function() { return new MyObj(); } };
    
    }());  
    </script>
    
    <script language='vbscript' runat='server'>
      Dim foo
      Set foo = Shim.construct()
       ...
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I can call it whatever, but just like there is a convention
(Yes I know I can call Java code from Scala; but that is pointless;
I know you can do this.GetType().FullName To get My.Current.Class But what can I call
I would like to understand how to retrieve the quotation from a top level
I know we can explicitly call the constructor of a class in C++ using
Is there a function I can call to know if a certain element is
I know you can pass arguments through the RunWorkerAsync function call when you first
How i can know the current method stack frame while a recursive call in
I know about AJAX cross-domain policy. So I can't just call http://www.google.com over a
I get a protected memory exception, but how can I know which call caused

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.