如何在原型模式下创建一个私有静态变量(How to create a private static variable in prototype pattern)
在下面的代码中,所有实例化的Page对象都从静态变量'nextId'获得它们的Id。 什么是重置nextId的最佳方法? 我不喜欢我这样做的方式,因为它是通过实例化对象访问的。 我宁愿做一些事情:
Page.reset()。 这怎么可能?
https://plnkr.co/edit/heOz52QxK6CExhe8Hdfm?p=preview
var Page = (function() { var nextId = 0; function Page(content) { this.id = nextId++; this.content = content; } Page.prototype.reset = function() { nextId = 0; } Page.prototype.show = function() { console.log(this.content + ' is ' + this.id); } return Page; }()) var a = new Page('a') a.show() // a is 0 var b = new Page('b') b.show() // b is 1 var c = new Page('c') c.show() // c is 2 a.reset() var d = new Page('d') d.show() // d is 0
In the code below, all instaniated Page objects get their Id from the static variable 'nextId'. What is the best way to reset nextId? I don't like the way I'm doing it because it's accessed through an instantiated object. I'd rather do something like:
Page.reset(). How is it possible?
https://plnkr.co/edit/heOz52QxK6CExhe8Hdfm?p=preview
var Page = (function() { var nextId = 0; function Page(content) { this.id = nextId++; this.content = content; } Page.prototype.reset = function() { nextId = 0; } Page.prototype.show = function() { console.log(this.content + ' is ' + this.id); } return Page; }()) var a = new Page('a') a.show() // a is 0 var b = new Page('b') b.show() // b is 1 var c = new Page('c') c.show() // c is 2 a.reset() var d = new Page('d') d.show() // d is 0
原文:https://stackoverflow.com/questions/39581592
最满意答案
在这里您可以下载“Email Reporter:VSTS 2008 Load Test Plug-in” http://code.msdn.microsoft.com/erep这是Mohammad Ashraful Alam撰写的一篇非常有用的文章。
Here you can download "Email Reporter: VSTS 2008 Load Test Plug-in" http://code.msdn.microsoft.com/erep It's a very helpful post by Mohammad Ashraful Alam.
相关问答
更多-
您可以将应用程序配置为使用控制台后端发送电子邮件。 它将电子邮件标准化,而不是发送它们。 更改您的settings.py以包括以下行: EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' 不要忘了删除它进行生产。 You can configure your application to use the Console Backend for sending e-mail. It writes e-mails to standa ...
-
VSTS没有测试可用(VSTS No test is available)[2019-12-11]
它是.Net Core测试,因此您可以通过.Net Core任务运行测试(版本: 2.* ;命令: test ;参数: - --configuration $(BuildConfiguration) ;检查发布测试结果选项)。 如果您使用1.*版本的.Net Core任务: 指定以下参数: - --configuration $(BuildConfiguration) --logger "trx" 添加发布测试结果任务(测试结果格式: VSTest ;测试结果文件: **\*.trx ;搜索文件夹: $(S ... -
如何通过电子邮件发送数据(How to send data trough email)[2022-05-16]
您可以在文件中写入列表并将其作为附件发送(gmail示例): protected bool ProcessButton_Click(object sender, EventArgs e) { SmtpClient client = new SmtpClient(); client.Host = "smtp.gmail.com"; client.Port = 587; client.Credentials = new NetworkCre ... -
VSTS全时间整合(VSTS all time integration)[2022-01-31]
简单的工作流程: 使用OAuth授权创建Web应用程序,请参阅本文: ASP.NET Web应用程序(OAuth示例) 用户使用“网站帐户”登录您的网站 登录后,启用链接(例如vsts-account),用户可以点击链接授权VSTS 将访问令牌和刷新令牌关联到该用户(存储在数据库中) 如果访问令牌过期,则使用刷新令牌获取访问令牌 使用访问令牌获取VSTS中的工作项 有关OAuth与VSTS的更多信息, 您可以参考使用OAuth 2.0授权访问REST API The simple workflow: Cre ... -
您无法获取Web App和ARM模板部署任务的输出,您可以通过调用Azure PowerShell或其他方式获取相关信息,例如: Get-AzureRmResourceGroup 。 关于在构建/发布期间发送电子邮件,您可以使用“发送网格电子邮件”或其他任务,仅根据您的要求或您的偏好。 更新: 简单的样本来获得输出: $r=New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName xxx -TemplateFi ...
-
要通过POST将数据移动到另一个页面,最简单的方法是将textarea包装在一个表单中并添加一个提交按钮: 您还 ...
-
在这里您可以下载“Email Reporter:VSTS 2008 Load Test Plug-in” http://code.msdn.microsoft.com/erep这是Mohammad Ashraful Alam撰写的一篇非常有用的文章。 Here you can download "Email Reporter: VSTS 2008 Load Test Plug-in" http://code.msdn.microsoft.com/erep It's a very helpful post b ...
-
您还可以使用junitreport任务中的XSL样式将XML文件转换为HTML。 http://ant.apache.org/manual/Tasks/junitreport.html 然后使用内置mail任务来邮寄此HTML文件
VSTS中dotnet核心项目的代码覆盖率和测试结果(Code coverage and test results for .NET Core projects in VSTS)[2022-01-29]
您可以使用Visual Studio Test任务和/framework:“.NETCoreApp,Version = v1.1”选项来运行.net核心测试。 (在Visual Studio测试任务中指定vstest.console.exe路径:C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Enterprise \ Common7 \ IDE \ Extensions \ TestPlatform) 有关代码覆盖率的文章: 使用代码覆盖率 ...更改配置以触发电子邮件以发送自动化测试结果(Change the configuration to trigger Email to send out the Automation Test Results)[2021-10-10]
您的电子邮件服务器是否永久关闭,您是否正在寻找替代电子邮件服务? 试试Gmail。 或者,即使您的电子邮件服务器暂时关闭,您是否正在寻找发送电子邮件的方法? 最简单的方法是在本地计算机上运行一个可以对消息进行排队的电子邮件服务器,直到真正的电子邮件服务器可用。 Was your email server shut down permanently and you're looking for a replacement email service? Try Gmail. Or are you looking ...相关文章
更多- 《wordpress插件制作视频教程》(How to create a wordpress plugin)全5集更新完毕[HDTV]
- 从 prototype.js 深入学习 javascript 的面向对象特性
- 原型模式
- 《Joomla 2.5 模板教程:宁皓网》(Create a Joomla 2.5 Template)前两章 + 模板资源[光盘镜像]
- Create a Bootable MicroSD Card
- java prototype 模式
- JAVA设计模式学习9——原型模式
- 基于prototype.js验证框架(validation.js)的三个应用
- Solr: a custom Search RequestHandler
- JavaFx Main中怎么绑定Java类中的一个static变量呢?
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。