Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I am a c++ programmer, Here is a C++ code, how to have similar JS code,
class A { public: void sayHello(); }; class B { public: A a; }; main() { B b; b.a.sayHello(); }
// Define class A function A() {} A.prototype.sayHello = function() { alert('hello!'); }; // Define class B function B() { this.a = new A(); } // Use them var b = new B(); b.a.sayHello();
Add a comment
The most basic and simplest example:
function A() { return { sayHello: function() { } } } function B() { return { a: new A() } } var b = new B(); b.a.sayHello();
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.