js方法创建的几种方式:
方法一
最常用的方法
function Test(){ alert("test"); }方法二
匿名函数
var test = function(){ alert("test"); }方法三
这种就比较原型了
(function{ alert("test"); })()方法四
在一个{}对象中存入一个方法,使用对象调用对象的方法。
var Test = { test:function(){ alert("test1"); } } var t = Test.test1();方法五
使用JavaScript的原型定义一个方法。
var Test = function(){};//定义一个空函数 //复制一个Test的原型对象,增加两个方法。 Test.PRototype= { test1:function(){ alert("test1"); }, test2:function(){ alert("test2"); } } 使用: var t = new Test(); t.test2();新闻热点
疑难解答