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)//添加颜色号
	
	}
相关推荐
程序猿的程2 小时前
开源一个 React 股票 K 线图组件,传个股票代码就能画图
前端·javascript
大雨还洅下2 小时前
前端JS: 虚拟dom是什么? 原理? 优缺点?
javascript
唐叔在学习2 小时前
[前端特效] 左滑显示按钮的实现介绍
前端·javascript
青青家的小灰灰3 小时前
深入理解事件循环:异步编程的基石
前端·javascript·面试
前端Hardy4 小时前
HTML&CSS&JS:打造丝滑的3D彩纸飘落特效
前端·javascript·css
前端Hardy4 小时前
HTML&CSS&JS:丝滑无卡顿的明暗主题切换
javascript·css·html
UIUV5 小时前
node:child_process spawn 模块学习笔记
javascript·后端·node.js
烛阴7 小时前
Three.js 零基础入门:手把手打造交互式 3D 几何体展示系统
javascript·webgl·three.js
颜酱7 小时前
单调栈:从模板到实战
javascript·后端·算法
_AaronWong8 小时前
Electron 实现仿豆包划词取词功能:从 AI 生成到落地踩坑记
前端·javascript·vue.js