I find myself in a situation where I need to create a web client interface that can interact with different types of hardware. The interface has a core component, and additional features depending on the hardware connected (specifically, the login() process varies per device).
As a C++ developer stepping into the realm of JavaScript extensions for this project, I must admit, I feel quite overwhelmed.
Here is the scenario I crafted for testing purposes:
Source1.js (considered as the universal base interface across all hardware):
function Login() {
this.type = 'login';
m_username = 'admin';
m_password = 'admin';
}
function Constructor() {
var mClass = new Login();
this.clicked = function() {
mClass.clicked();
}
this.getLogin = function() {
return mClass;
}
}
g_constructor = new Constructor();
Source2.js (contains the custom implementation of Login().clicked()):
function Login() {
this.clicked = function() {
document.getElementById("TextHere").innerHTML = m_username + ":" + m_password;
}
}
The HTML File used for testing:
<html lang="en">
<head>
<title>JavaScript Test</title>
<meta charset="utf-8" />
<script src="source1.js"> </script>
<script src="source2.js"> </script>
</head>
<body>
<button onClick="g_constructor.clicked()">Test</button>
<p> </p>
<div id="TextHere">Text</div>
</body>
</html>
In my usual domain of C++, I typically rely on virtual base classes for such implementations. However, when it comes to JavaScript, I am at a loss. Can someone point me in the right direction on how to achieve a similar structure? Specifically, ensuring that every object of Login() type possesses the clicked() function as defined in Source2.js.