例子:
JS文件:
function Controller() {
self = this;
self.createObject = createObject;
function createObject() {
new ObjectTest(self);
}
self.createAlert = createAlert;
function createAlert(text) {
alert(text);
}
}
function ObjectTest(controller) {
this.controller = controller;
this.controller.createAlert("test");
}
HTML 文档 - 构造对象并执行方法
<body onload="new Controller.createObject()">
这将给出错误消息:
Uncaught TypeError: Object #<Controller> has no method 'createAlert'