您的位置:首页 > Web前端 > JavaScript

javascript之中文编程。

2016-05-12 00:00 435 查看
摘要: 中国人,用中文!

首先,我们用javascript封装一个简单的中文数学函数。

[code=plain]<script>
;(function(温逗死){
温逗死.中文 = {
加法:function(o){return o.reduce(function(a,b){return a + b});},
减法:function(o){return o.reduce(function(a,b){return a - b});},
乘法:function(o){return o.reduce(function(a,b){return a * b});},
除法:function(o){return o.reduce(function(a,b){return a / b});},
取余:function(o){return o.reduce(function(a,b){return a % b});},
警报:function(o){alert(o);}
}
})(window)
</script>

2.然后,我们写一个html文件。

[code=plain]​
<!doctype html>
<html>
<head>
<title>js中文编程数学函数</title>
<meta charset="utf8" />
</head>
<body>
<script>
中文.警报(中文.加法([1,2,3,4,5,6,7,8,9]));
</script>
</body>
</html>

​


3.最后,看弹出来什么。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息