In Swift I can instantiate one class within another as a property and call its methods using something like:
newClass.anotherClass.methodInTheOtherClass();
I am unable to do that in JavaScript. The following code produces an error in this line:
var cowCommunication = new CowCommunication();
What is the proper way to achieve this goal, and make the following script work?
<html >
<script type = "text/javascript" >
let CowCommunication = {
sayMoo: function() {
alert("hey");
}
};
let farmTools = {
var cowCommunication = new CowCommunication();
};
farmTools.cowCommunication.sayMoo();
</script>
</html >
This is a real example of code I am actually trying to make work.
varkeyword inside of an object initializer in javascript, that's your main problem. look up the correct way to instantiate objects in javascript.