7-12 WPS JS宏 this、return用构造函数自定义类-1:对象内部函数,外部调用的写法

7-12 WPS JS宏 this return用构造函数自定义类-1:自定义类内部函数,外部调用的写法

一、函数

this:

function Ceshi(){ } 过程名Ceshi

参数: this.num=99999

return

返回 所需

参数: return arr

二、测试代码

function Ceshi(){

//自定义类内部函数的写法:

//属性普通值的写法:

this.num=99999,

//属性值函数的写法:

//写法只有一种,this=过程名Ceshi,键为Sum,分隔符为=,值为function(arr){},return有返回值

this.Sum=function(arr){return arr.reduce((x,y)=>x+y)},

this.Max=function(arr){return arr.reduce((x,y)=>(x>y)?x:y)},

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

}

function Diaoyong()

{

//调用自定义类内容:

//创建激活new Ceshi()自定义类,激活后才可调用自定义类中的函数。

//方法1:

Console.log( new Ceshi().num);

//方法2:

var obj=new Ceshi();

Console.log(obj.Sum([12,112,13]));

Console.log(obj.Max([31,142,65]));

obj.Rngcolor(Range("a1:c5"),44);

}

javascript 复制代码
//7-12 WPS JS宏 this用构造函数自定义类-1:对象内部函数,外部调用的写法
function Ceshi(){
	//对象内容函数的写法:

		//属性普通值的写法:
		this.num=99999,
		
		//属性值函数的写法:
		//写法只有一种,this=过程名Ceshi,键为Sum,分隔符为=,值为function(arr){},return有返回值
		this.Sum=function(arr){return arr.reduce((x,y)=>x+y)},
		

		this.Max=function(arr){return arr.reduce((x,y)=>(x>y)?x:y)},
		
	
		this.Rngcolor=function(rng,color){rng.Interior.ColorIndex=color}

		}


function Diaoyong()
{
//调用对象内容:
//创建激活new Ceshi()自定义类对象,激活后才可调用自定义类对象中的函数。
//方法1:
Console.log( new Ceshi().num);

//方法2:
var obj=new Ceshi();

Console.log(obj.Sum([12,112,13]));
	Console.log(obj.Max([31,142,65]));
		obj.Rngcolor(Range("a1:c5"),44);
}
相关推荐
用户新2 小时前
V8引擎 精品漫游指南--Ignition篇(下 一) 动态执行前的事情
前端·javascript
@PHARAOH3 小时前
WHAT - GitLens vs Fork
前端
yqcoder3 小时前
前端性能优化:如何减少重绘与重排?
前端·性能优化
洋子4 小时前
Yank Note 系列 13 - 让 AI Agent 进入笔记工作流
前端·人工智能
wenzhangli76 小时前
Ooder A2UI 核心架构深度解析:WEB 拦截层的设计与实现
前端·架构
前端百草阁7 小时前
【前端性能优化全链路指南】从开发编写到构建运行的多维度实践
前端·性能优化
神探小白牙7 小时前
eCharts 多系列柱状图增加背景图
javascript·ecmascript·echarts
女生也可以敲代码7 小时前
AI时代下的50道前端开发面试题:从基础到大模型应用
前端·面试
ZhengEnCi7 小时前
M5-markconv自定义CSS样式指南 📝
前端·css·python
IT_陈寒8 小时前
SpringBoot自动配置的坑差点让我加班到天亮
前端·人工智能·后端