我想调用一个函数,甚至在对象图区域中创建一个函数。
它是如何正常工作的?这就是我得到的。虽然不起作用......
var _images = {
test: {
path: 'test.jpg',
areas: [{
coords: '211,38,238,60',
text: 'let me test it',
//onclick: .... ?
obj = function() {
this.hello = function hello() {}
alert("Hello");
}
}]
},
}
var asdf = new obj();
asdf.hello();
答案 0 :(得分:1)
Javascript对象函数是“:”而不是“=”!您可以根据需要调用新实例对象作为其路径...如下所示
var _images = {
test: {
path: 'test.jpg',
areas: [{
coords: '211,38,238,60',
text: 'let me test it',
//onclick: .... ?
obj : function() {
this.hello = function hello() {}
alert("Hello");
}
}]
},
}
var asdf = new _images.test.areas[0].obj();
asdf.hello();
答案 1 :(得分:-2)
对象属性应该用:
var _images = {
test: {
path: 'test.jpg',
areas: {
coords: '211,38,238,60',
text: 'let me test it',
//onclick: .... ?
obj:function() {
this.hello = function hello() {};
console.log('hello')
}
}
}
};
var asdf = new _images.test.areas.obj();
asdf.hello();