Below is some example code that explains the error:
HTML:
<!DOCTYPE HTML>
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Widget Test</h1>
<script type="text/javascript">
(function() {
var script = document.createElement('script'); script.type = 'text/javascript';
script.async = true;
script.src = 'http://localhost/job/widget.js';
var s = document.getElementsByTagName('head')[0].appendChild(script);
})();
</script>
<div id="list" data-cnumber="21"></div>
</body>
</html>
widget.js:
(function() {
var a = new app();
var a1 = new app1();
function app() {
this.a;
this.b;
}
app.prototype.add = function () {
};
function app1() {
this.a;
this.b;
this.c;
this.add();
}
app1.prototype.add = function () {
};
})();
- This is the error - "Uncaught TypeError: Object # has no method 'add' "
- On doing console.log of both the objects, I can see their properties, but for some reason not their methods.
What's wrong?