7-12 WPS JS宏 this、return用构造函数自定义类-1:对象内部函数,外部调用的写法

7-12 WPS JS宏 this return用构造函数自定义类-1:自定义类内部函数,外部调用的写法

一、函数

this:

function Ceshi(){ } 过程名Ceshi

参数: this.num=99999

return

返回 所需

参数: return arr

二、测试代码

function Ceshi(){

//自定义类内部函数的写法:

//属性普通值的写法:

this.num=99999,

//属性值函数的写法:

//写法只有一种,this=过程名Ceshi,键为Sum,分隔符为=,值为function(arr){},return有返回值

this.Sum=function(arr){return arr.reduce((x,y)=>x+y)},

this.Max=function(arr){return arr.reduce((x,y)=>(x>y)?x:y)},

this.Rngcolor=function(rng,color){rng.Interior.ColorIndex=color}

}

function Diaoyong()

{

//调用自定义类内容:

//创建激活new Ceshi()自定义类,激活后才可调用自定义类中的函数。

//方法1:

Console.log( new Ceshi().num);

//方法2:

var obj=new Ceshi();

Console.log(obj.Sum([12,112,13]));

Console.log(obj.Max([31,142,65]));

obj.Rngcolor(Range("a1:c5"),44);

}

javascript 复制代码
//7-12 WPS JS宏 this用构造函数自定义类-1:对象内部函数,外部调用的写法
function Ceshi(){
	//对象内容函数的写法:

		//属性普通值的写法:
		this.num=99999,
		
		//属性值函数的写法:
		//写法只有一种,this=过程名Ceshi,键为Sum,分隔符为=,值为function(arr){},return有返回值
		this.Sum=function(arr){return arr.reduce((x,y)=>x+y)},
		

		this.Max=function(arr){return arr.reduce((x,y)=>(x>y)?x:y)},
		
	
		this.Rngcolor=function(rng,color){rng.Interior.ColorIndex=color}

		}


function Diaoyong()
{
//调用对象内容:
//创建激活new Ceshi()自定义类对象,激活后才可调用自定义类对象中的函数。
//方法1:
Console.log( new Ceshi().num);

//方法2:
var obj=new Ceshi();

Console.log(obj.Sum([12,112,13]));
	Console.log(obj.Max([31,142,65]));
		obj.Rngcolor(Range("a1:c5"),44);
}
相关推荐
har01d2 小时前
AI生成的 vue3 日历组件,显示农历与节日,日期可选择,年月可切换
前端·vue.js·节日
HIT_Weston2 小时前
106、【Ubuntu】【Hugo】搭建私人博客:模糊搜索 Fuse.js(二)
linux·javascript·ubuntu
冲刺逆向2 小时前
【js逆向案例六】创宇盾(加速乐)通杀模版
java·前端·javascript
我穿棉裤了2 小时前
文字换行自动添加换行符“-”
前端·javascript·vue.js
six+seven2 小时前
Node.js内置模块fs
前端·node.js
少莫千华2 小时前
【HTML】CSS绘制奥运五环
前端·css·html
沛沛老爹2 小时前
Web开发者转型AI安全核心:Agent Skills沙盒环境与威胁缓解实战
java·前端·人工智能·安全·rag·web转型升级
仰泳之鹅2 小时前
【杂谈】C语言中的链接属性、声明周期以及static关键字
java·c语言·前端
2501_940315262 小时前
【无标题】(leetcode933)最近的请求次数
java·前端·javascript