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)//添加颜色号
	
	}
相关推荐
程序员Sunday5 分钟前
React 的 useEffect 怎么工作?依赖数组、清理函数和重复执行如何理解?
前端·javascript
ESDWAN9 分钟前
海外股票网络环境优化与交易场景应用:从行情获取到交易系统稳定性设计
开发语言·网络·php
西柚不烦恼12 分钟前
jenkins版本和java版本的依赖
java·开发语言·jenkins
stellanke16 分钟前
工业化C++:3. 继承、虚函数与运行时多态:从水果加工到日志策略设计
开发语言·c++
Matlab程序猿21 分钟前
【MATLAB源码-第460期】基于matlab的OTFS通信系统SLM峰均比抑制及非线性功率放大器失真与误码性能仿真
开发语言·算法·matlab·slm·otfs
kimnoic25 分钟前
Python变量与数据类型全解析(最新整理)
开发语言·python
豆角焖肉30 分钟前
SpringBoot+JWT 实现前后端分离登录鉴权
java·开发语言·spring boot·jwt·前后端分离·登录认证
程序员Sunday38 分钟前
Vue 3 响应式原理是什么?Proxy、ref 和 reactive 有什么区别?
前端·javascript
Wang's Blog39 分钟前
Java 项目部署之 Docker工具快速入门: 自定义镜像的分层结构与写时复制
java·开发语言·docker
mldong1 小时前
一个 npm 包,九页审批中心:Vue3 项目接上工作流引擎
前端·javascript·vue.js