7-13 WPS JS宏 this 用构造函数自定义类-2,调用内部对象必须用this

7-13 WPS JS宏 this 用构造函数自定义类-2,调用内部对象必须用this

一、函数

this:

指 function Ceshi(){ } 过程名Ceshi ,在自定义类内部调用内部对象必须加this.

参数: this.num=99999

参数: this.Max=this.arr.reduce((x,y)=>(x>y)?x:y)

二、测试代码

function custom(Rngs){

this.Num=Rngs.Cells.Count,

this.arr=Rngs.Value().flat(),

this.Sum=function(){return this.arr.reduce((x,y)=>x+y)},//调用内部对象如:arr,必须在前方加this

this.Max=this.arr.reduce((x,y)=>(x>y)?x:y),//调用内部对象如:arr,必须在前方加this

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

}

function test(){

var total=new custom(Range("b2:d2"));//自定义类添加单元格区域,后面调用函数就不需要再添加单元格区域。如下:

Console.log(total.Max);

Console.log(total.Sum());

total.Rngcolor(9)//添加颜色号

var demo=new custom(Range("b4:d10"));//可同时对多个区域使用自定义类

Console.log(demo.Max);

Console.log(demo.Sum());

demo.Rngcolor(5)//添加颜色号

}

javascript 复制代码
//7-13 WPS JS宏 this 用构造函数自定义类-2,调用内部对象必须用this
function custom(Rngs){
	this.Num=Rngs.Cells.Count,
	this.arr=Rngs.Value().flat(),
	this.Sum=function(){return this.arr.reduce((x,y)=>x+y)},//调用内部对象如:arr,必须在前方加this
	this.Max=this.arr.reduce((x,y)=>(x>y)?x:y),//调用内部对象如:arr,必须在前方加this
	this.Rngcolor=function(color){Rngs.Interior.ColorIndex=color}
	}
function test(){
	var total=new custom(Range("b2:d2"));//自定义类添加单元格区域,后面调用函数就不需要再添加单元格区域。如下:
		Console.log(total.Max);
		Console.log(total.Sum());
		total.Rngcolor(9)//添加颜色号
	var demo=new custom(Range("b4:d10"));//可同时对多个区域使用自定义类
		Console.log(demo.Max);
		Console.log(demo.Sum());
		demo.Rngcolor(5)//添加颜色号
	
	}
相关推荐
znsoft4 分钟前
MaClaw(码卡龙)技术拆解:一个 Go + React 的可自进化智能体平台
开发语言·react.js·golang
凉茶钱2 小时前
红黑树:用“颜色”换“平衡”,set 与 map 的底层发动机
开发语言·c++·红黑树
高冷小鱼殿下2 小时前
内部类Lambda与枚举
java·开发语言
栉甜2 小时前
Vue2学习内容(上)
前端·javascript·vue.js·学习
shelly聊外贸2 小时前
WhatsApp 聊天记录如何导出为 CSV?使用 Python 进行数据分析
开发语言·python·数据分析
octopus_c3 小时前
C++ 模板详解:函数模板、类模板、特化与分离编译
开发语言·c++·算法
shmily麻瓜小菜鸡3 小时前
TypeScript 知识点补充(第三部分:工程化与高级类型)
前端·javascript·typescript
椒颜皮皮虾྅4 小时前
让文档不止于文字:DeploySharp + PP-Structure,打通版面分析与表格重建
开发语言·学习·c#·.net·cuda
Eider19984 小时前
Python基础知识之并发相关-2
开发语言·前端·python
第九序言T4 小时前
Python 数据处理进阶(二十二)用 Pandas 做一次完整的用户行为分析
开发语言·python·数据分析·pandas