JS做成像程序中的类一样

JS做成像程序中的类一样


如我有
Tools.js文件
里面有一个
function MessageShow(message)
{
    Alert(message);
}
function Show(message)
{
    Alert(message);
}

现在如果把文件引入网页的话调用是:
MessageShow("测试");

但现在我想要用
Tools.MessageShow("类形式调用");

这种方式,我的文件要怎么改动

谢谢

 

var Tools = {
MessageShow:function(message){alert(message)},
Show:function(message){alert(message)}
}

 

 

方式一:function way// First, define some functions that will be used as methods.

function Rectangle_area(  ) { return this.width * this.height; }

function Rectangle_perimeter(  ) { return 2*this.width + 2*this.height; }

function Rectangle_set_size(w,h) { this.width = w; this.height = h; }

function Rectangle_enlarge(  ) { this.width *= 2; this.height *= 2; }

function Rectangle_shrink(  ) { this.width /= 2; this.height /= 2; }

 

// Then define a constructor method for our Rectangle objects.

// The constructor initializes properties and also assigns methods.

function Rectangle(w, h)

{

    // Initialize object properties.

    this.width = w;

    this.height = h;

 

    // Define methods for the object.

    this.area = Rectangle_area;

    this.perimeter = Rectangle_perimeter;

    this.set_size = Rectangle_set_size;

    this.enlarge = Rectangle_enlarge;

    this.shrink = Rectangle_shrink;

}

// Now, when we create a rectangle, we can immediately invoke methods on it:

var r = new Rectangle(2,2);

alert(r.area());

alert(r.enlarge());

alert(r.perimeter());  方式二:prototype way(better)prototype way is better than function way!
because it takes up less memory space.//solution 2:
//this solution is better than solution 1
//use object's prototype
// Define a constructor method for our class.
// Use it to initialize properties that will be different for
// each individual Circle object.
function Circle(x, y, r)
{
    this.x = x;  // The X-coordinate of the center of the circle
    this.y = y;  // The Y-coordinate of the center of the circle
    this.r = r;  // The radius of the circle
}
 
// Define a constant: a property that will be shared by
// all circle objects. Actually, we could just use Math.PI,
// but we do it this way for the sake of instruction.
Circle.prototype.pi = 3.14159;
 
// Define a method to compute the circumference of the circle.
// First declare a function, then assign it to a prototype property.
// Note the use of the constant defined above.
function Circle_circumference(  ) { return 2 * this.pi * this.r; }
Circle.prototype.circumference = Circle_circumference;
 
// Define another method. This time we use a function literal to define
// the function and assign it to a prototype property all in one step.
Circle.prototype.area = function(  ) { return this.pi * this.r * this.r; }
 
// The Circle class is defined.
// Now we can create an instance and invoke its methods.
var c = new Circle(0.0, 0.0, 3);//radius=2
alert(c.area());
alert(c.circumference());
 
/*
*Notes:
*It is not only user-defined classes that have prototype objects.
*Built-in classes, such as String and Date,
*have prototype objects too, and you can assign values to them.
*For example, the following code defines a new method that is available for all String objects:
*/ String.prototype.Trim = function()
{
    return this.replace(/(^/s*)|(/s*$)/g, "");
}
String.prototype.LTrim = function()
{
    return this.replace(/(^/s*)/g, "");
}String.prototype.RTrim = function()
{
    return this.replace(/(/s*$)/g, "");
}alert("A ".Trim()+" B".Trim())

内容概要:本研究聚焦于“绿电直连型电氢氨园区”的优化运行,提出一种直接利用绿色电力驱动制氢与合成氨的综合能源系统架构。通过构建包含风/光发电、电解水制氢、氢气储存、合成氨反应及电能直供等关键环节的系统模型,研究旨在实现能源的高效转化与梯级利用,降低对外部电网依赖,提升园区能源自洽率与经济性。研究综合运用Matlab与Python工具进行建模与仿真,结合实际气象与负荷数据,对系统在不同工况下的运行策略、能量流动、设备容量配置及经济技术指标进行深入分析与优化,并形成完整的Word论文文档,为新型零碳产业园区的规划与建设提供了理论依据和技术支撑。; 适合人群:具备新能源、电力系统、化工或综合能源系统背景的科研人员,以及从事园区规划、能源管理、低碳技术开发的工程技术人员。; 使用场景及目标:①研究绿电如何高效耦合至化工生产流程,实现“电-氢-氨”多能互补;②掌握综合能源系统(IES)的建模、仿真与优化方法,特别是多时间尺度下的运行调度策略;③为撰写高水平学术论文或完成相关课题研究积累数据、代码与写作模板。; 阅读建议:此资源包含代码、数据和完整论文,建议使用者先通读Word论文以理解整体框架与理论基础,再结合Matlab/Python代码进行复现与调试,最后可基于提供的数据和模型进行二次开发,以深化对绿电综合利用技术的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值