由于某些原因,我无法将设置方法中的函数调用到init方法中。
// this is how I use it now(dont work)
Plugin.prototype = {
settings: function(){
function hello(name){
alert('hi, '+name)
}
},
init: function(){
this.settings()
hello('John Doe')
}
}发布于 2012-12-11 08:32:29
这可能就是你想说的:
Plugin.prototype = {
settings: function(){
},
hello: function(name){
alert('hi, '+name);
},
init: function(){
this.settings();
this.hello('John Doe');
}
};或者,如果你想让hello()成为私有的,你可以这样做:
Plugin.prototype = function(){
var hello = function (name){
alert('hi, '+name);
};
return {
settings: function(){
},
init: function(){
this.settings();
hello('John Doe');
}
};
}();jsfiddle
https://stackoverflow.com/questions/13811231
复制相似问题