在我的模块中,我想让一些变量和函数向公众公开,但我不确定应该以哪种方式编写。
<script type="text/javascript">
YUI.add('my-module1', function (Y) {
Y.namespace("MyModule1");
var privateVar='some data';
var privateFunc=function(){...};
/*should I do it like this?*/
Y.MyModule1.publicVar='some data';
Y.MyModule1.publicFunc=function(){...};
/*or is this correct if I do it like this?*/
var publicVar='some data';
var publicFunc=function(){...};
return{
publicVar: publicVar,
publicFunc: publicFunc
};
}, '0.0.1', {
requires: []
});
</script>