<script type="text/javascript">
(function () {
var customService = function () {
};
customService.prototype = {
open: function () {
contents: this._getHtml(),
},
close: function () {
},
_getHtml: function () {
var html = [];
Array.prototype.push.call(html,
'<div class=\"content\">',
'<div>1、</div>',
'<div>2、<\/div>',
'<div>3、<\/div>',
'<div>4、<\/div>',
'<\/div>'
);
return html.join('');
}
};
window.CustomService = new customService();
})();
</script>
1、请问Array.prototype.push.call这个是什么意思??
2、window.CustomService = new customService();这样做有什么好处???
3、还有为什么
(function(){
})();
这样的匿名函数会立即执行?
解决方案 »
- 各位前辈,有问题需要大家帮助 ,谢谢
- 请教如何实现类似126邮箱的web多文档窗口?
- 如何在前台 控制想要上传文件的大小啊?
- 求一javascript函数可以验证文件名是否合法的
- 各位帮忙看看,谢谢大家了,一道css,js的问题
- javascript中如何强制变量声明呢?好象vbscript中可以的,js中可以吗?
- 判断滚动条是否已到顶部!
- 模式窗体能否返回模式?
- 如何去掉用window.showModalDialog打开的窗口的标题栏?
- 如何使用客户端技术(如javascript,applet等),取得客户端的IP?
- ■■■ JS 传参 (大疑问) ■■■
- 怎么样可以使iframe的高度随着内嵌网页内容的高度的变化而一致?
问题2: 全局变量的声明 就像alert一样 可以直接使用 其本质就是window.alert
问题3:相当于 var aaa = function(){} aaa();
大哥,第一个问题能不能再解释解释??
Array.prototype.push的意思是调用数组对象原型里的push方法,push你知道吧?在数组尾压入一个元素,用call来调用就是调用push方法的对象是call的第一个参数,即html,其实就相当于html.push();
<script type="text/javascript">
/*这个是匿名函数,即立即执行函数,相当于声明一个函数让他立即执行,具体如1楼大神问题三描述那样。这里用匿名函数包裹下面执行的代码的用意是创建一个执行环境,防止像customService 这样的变量成为全局变量。*/
(function () {
var customService = function () {
};
customService.prototype = {
open: function () {
contents: this._getHtml(),
},
close: function () {
},
_getHtml: function () {
var html = [];
/*call方法的用意是指定函数执行的上下文,方法的第一个参数即新的函数上下文,也就是说我可以用html去调用push方法,第二个参数是传入push方法的参数*/
Array.prototype.push.call(html,
'<div class=\"content\">',
'<div>1、</div>',
'<div>2、<\/div>',
'<div>3、<\/div>',
'<div>4、<\/div>',
'<\/div>'
);
return html.join('');
}
};
/*这里相当于给customService类创建一个namespace,因为window对象可以省略,以后你在使用customService类时可以这样CustomService.customService*/
window.CustomService = new customService();
})();
</script>
例如:for(var name in Array.prorotype){
console.log(name);
}
那单独用Array.prototype是什么意思,和Array有什么区别。
console.log(name);
}这是遍历访问Array的原型属性名称