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 小时前
TypeScript 类型体操练习笔记(二)
前端·typescript
光影少年3 小时前
浏览器渲染原理?
前端·javascript·前端框架
小白探索世界欧耶!~3 小时前
Vue2项目引入sortablejs实现表格行拖曳排序
前端·javascript·vue.js·经验分享·elementui·html·echarts
叫我一声阿雷吧4 小时前
JS实现响应式导航栏(移动端汉堡菜单)|适配多端+无缝交互【附完整源码】
开发语言·javascript·交互
GISer_Jing4 小时前
前端营销(AIGC II)
前端·react.js·aigc
NEXT065 小时前
深度解析 JWT:从 RFC 原理到 NestJS 实战与架构权衡
前端·typescript·nestjs
程序员林北北6 小时前
【前端进阶之旅】节流与防抖:前端性能优化的“安全带”与“稳定器”
前端·javascript·vue.js·react.js·typescript
寻星探路6 小时前
【前端基础】HTML + CSS + JavaScript 快速入门(三):JS 与 jQuery 实战
java·前端·javascript·css·c++·ai·html
未来之窗软件服务7 小时前
未来之窗昭和仙君(六十九)前端收银台行为异常检测—东方仙盟练气
前端·仙盟创梦ide·东方仙盟·昭和仙君
大叔编程奋斗记8 小时前
两个日期间的相隔年月计算
前端·salesforce