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)//添加颜色号
	
	}
相关推荐
551只玄猫1 小时前
【数学建模 matlab 实验报告12】聚类分析和判别分析
开发语言·数学建模·matlab·课程设计·聚类·实验报告
小陈工3 小时前
Python Web开发入门(十七):Vue.js与Python后端集成——让前后端真正“握手言和“
开发语言·前端·javascript·数据库·vue.js·人工智能·python
H Journey3 小时前
C++之 CMake、CMakeLists.txt、Makefile
开发语言·c++·makefile·cmake
午安~婉7 小时前
Electron桌面应用聊天(续)
前端·javascript·electron
lly2024067 小时前
C 标准库 - `<stdio.h>`
开发语言
沫璃染墨7 小时前
C++ string 从入门到精通:构造、迭代器、容量接口全解析
c语言·开发语言·c++
jwn9997 小时前
Laravel6.x核心特性全解析
开发语言·php·laravel
迷藏4947 小时前
**发散创新:基于Rust实现的开源合规权限管理框架设计与实践**在现代软件架构中,**权限控制(RBAC)** 已成为保障
java·开发语言·python·rust·开源
功德+n8 小时前
Linux下安装与配置Docker完整详细步骤
linux·运维·服务器·开发语言·docker·centos
明日清晨8 小时前
python扫码登录dy
开发语言·python