利用面向对象的方式来使用JS
发布日期:2021-05-14 04:37:05 浏览次数:14 分类:博客文章

本文共 2164 字,大约阅读时间需要 7 分钟。

���������������������������������������JS������������������������������

<
script type
=
"
text/javascript
"
>
function
product(a,b) {
return
a
*
b; }
<
/
script>
<
/
head>
<
body
>
<
script type
=
"
text/javascript
"
>
document.write(product(
4
,
3
));
<
/
script>

������ ������������������������������������,���body���������product���������������js���������

���������������������������������������������������

���������������������airthmaticOperation���������

function
airthmaticOperation(){}

��������������������������������������������������������������������������������� ���������������������������������������������������js������������������������prototype������������������������������������������������������������������������������������

airthmaticOperation.prototype.addition 
=
function
(a,b)
{ ������
 
������return
a
+
b;
}
airthmaticOperation.prototype.multiply
=
function
(a,b)
{ ������
 
������return
a
*
b;
}

������ ���������������������������������������������������������������������������������

var
objMyClass
=
new
aithmaticOperation();

���������������������

var
resultAdd
=
objMyClass.addition(a,b);
 
var
resultMul
=
objMyClass.multiply(a,b);

���������������������������������������������������������������������������������������������������������������������������������������������������

 
var
Arithmetic
=
function
(){
������var
obj
=
{
������������������������������add:
function
(a,b) {
return
a
+
b; },
������������������������������multiply:
function
(a,b) {
return
a
*
b; }
������������������������};
������return
obj;
}();

���������������������������������������������������������������

var
resultAdd
=
Arithmetic.add(a,b);
var
resultMul
=
Arithmetic.multiply(a,b);

���������������������~~~

上一篇:HTTPModules与HTTPHandler【转】
下一篇:Oracle分页之三:利用PagerView来实现无刷新GridView

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2025年05月05日 07时03分47秒