prototype是指对象的原型。
Function.prototype.extend=function(properties){};这样写后, 没有一个Function对象都有extend 这个方法了。他和Function.extend 是不一样的。你用Function.extend();这样写是不对的。现在来测试一下:
<script>
// Function.prototype.extend = function(){};
String.prototype.extend = function(){alert(1)};
alert(Function.extend)
alert(Function.prototype.extend)
alert(String.extend)
alert(String.prototype.extend)
</script>结果:
undefined
undefined
undefined
function(){alert(1)}再来打测试::
<script>
Function.prototype.extend = function(){alert(2)};
String.prototype.extend = function(){alert(1)};
Function.extend();
String.extend();
alert(Function.extend)
alert(Function.prototype.extend)
alert(String.extend)
alert(String.prototype.extend)
</script>结果:
2
2
function(){alert(2)}
function(){alert(2)}
function(){alert(2)}
function(){alert(1)}从结果可以看出:Function.extend()和String.extend()都是调用的Function.prototype.extend方法。
Function.prototype.extend=function(properties){};这样写后, 没有一个Function对象都有extend 这个方法了。他和Function.extend 是不一样的。你用Function.extend();这样写是不对的。现在来测试一下:
<script>
// Function.prototype.extend = function(){};
String.prototype.extend = function(){alert(1)};
alert(Function.extend)
alert(Function.prototype.extend)
alert(String.extend)
alert(String.prototype.extend)
</script>结果:
undefined
undefined
undefined
function(){alert(1)}再来打测试::
<script>
Function.prototype.extend = function(){alert(2)};
String.prototype.extend = function(){alert(1)};
Function.extend();
String.extend();
alert(Function.extend)
alert(Function.prototype.extend)
alert(String.extend)
alert(String.prototype.extend)
</script>结果:
2
2
function(){alert(2)}
function(){alert(2)}
function(){alert(2)}
function(){alert(1)}从结果可以看出:Function.extend()和String.extend()都是调用的Function.prototype.extend方法。
解决方案 »
- VS2005使用jquery框架.ajax方法调用页面后台方法不能正常运行,VS2010能运行
- aptana不会安装 请好心人帮忙下
- 问一个event的问题
- onclick事件不响应,再次请教!
- 页面内容是用document.write方法写出的,那有什么方法等到此页面的所有元素?
- 如何让分帧随这纳入的网页变长而变长
- 页面初始化事件叫什么名字,比如VbScript里的window_onload?
- 征VBScript和JavaScript使用心得
- 为什么有些属性在IE6好用,在IE5就不好用了。
- visual studio 2013 调试 nodejs 问题, debugger listening on port 5858
- 请哥哥,姐姐们 解释这里的JS代码的意思 谢谢啦!
- 网页的放大缩小?
what are you doing ?????貌似没看清我的问题吧
a.prototype.extend = function x(){}
var b = new a();
alert(b instanceof a)//true
alert(b.constructor)//function(){}
alert(b.extend +"\r\n"+ a.prototype.extend)//这个不难理解
就我所知道的,实际上Function是Function对象的实例化对象(-_-#)。
这点LZ可以通过以下代码证明:alert(Function instanceof Function);//true
alert(Function.constructor)
/*
输出
function Function() {
[native code]
}
*/很怪吧?所以Function.prototype.extend 和 Function.extend是同个函数体。