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方法。
解决方案 »
- 弱弱的问下:怎么写判断是否按下shift键后执行?(不是按下时)
- JSLab带你进入WEB APP的世界
- 浏览器变化 如何获得 页面div的 大小呢 通过js 急呀求帮助
- 按一定的概率显示图片
- javascript的自下而上的循环滚动文字如何改成自右而左滚动?
- 一个到时提醒功能
- 超难问题!!!!! 如何 用 javascript 实现 表格 的列头 通过 鼠标 拖动 列之间的位置进行对调 ???????急!!!!!!!!
- 如何有效拆分类如"1_2_20_30_"的字符串
- 高手看看这个奇怪的问题!!!!!!!
- 如何保存一个文件
- 请哥哥,姐姐们 解释这里的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是同个函数体。