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)//添加颜色号
	
	}
相关推荐
小羊没烦恼!12 小时前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
三十而立洋13 小时前
Cookie 详解:从产生到安全,一次讲透
前端·javascript
伞伞悦读13 小时前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
卡布鲁13 小时前
把一个 Vite + Vue3 应用塞进 qiankun (React + Umi3) 主站:十个坑的复盘
前端·javascript·react.js
C语言小火车14 小时前
C/C++ 为什么需要编译器?
开发语言·c++
李少兄14 小时前
JavaScript 隐式全局变量解析
javascript
霍霍的袁15 小时前
【C++】map 和 set 的使用 | 从用法到底层
开发语言·c++·学习·visual studio
孙启超15 小时前
【AI开发之Rust】第 11 课:智能指针与内部可变性
开发语言·后端·rust
此生决int15 小时前
深入理解C++系列(20)——C++11(下)
开发语言·c++
沙蒿同学16 小时前
我用 Go 搭了一条 AI Agent 流水线:从 1 张商品图到一整套淘宝详情页
前端·javascript·后端