简体   繁体   English

我试图找出它叫什么

[英]I'm trying to find out what it's called

Is there an easier way to achieve this in JavaScript?有没有更简单的方法可以在 JavaScript 中实现这一点? For example without creating a function?例如不创建函数? And what is it called?它叫什么?

Thank you谢谢

 function testmulti(id,name) { this.id = id; this.name = name; } var test3 = new Array(); test3=new testmulti("4","toto2"); console.log(test3);

It's called an object.它被称为对象。 In variable test3 there is object and it can be created explicit or by function.在变量test3有对象,它可以显式创建或通过函数创建。 In my example you can create only single object.在我的示例中,您只能创建单个对象。 In your example you have builder pattern, which allows you to create multiple, different objects.在您的示例中,您有构建器模式,它允许您创建多个不同的对象。

 test3 = { id: '4', name: 'toto2' }; console.log(test3);

In Javascript ES6 onwards, you can create a class for an entity like this:在 Javascript ES6 之后,您可以为这样的实体创建一个类:

class Rectangle {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
}

And then, create an object of the class like below:然后,创建一个类的对象,如下所示:

const square = new Rectangle(10, 10);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何找出对象的onclick事件调用的javascript函数? - How do I find out what javascript function is being called by an object's onclick event? 尝试找出jQuery中是否有错误或我在做什么 - Trying to figure out if there is a bug in jQuery or if it's something I'm doing 我正在学习Javascript,试图找出为什么我的“摇滚剪刀”游戏无法正常工作。 。 - I'm learning Javascript, I'm trying to find out why my “Rock paper scissors” game wont work . . 在离开网页时,我可以使用什么工具找出正在调用的JavaScript事件? - What tool can I use to find out what JavaScript events are being called when leaving a web page? 如何找出我正在使用的 jQuery 版本? - How can I find out what jQuery version I’m using? 我正在尝试 .Find() 一个 Div 内的 TextArea - I'm trying to .Find() a TextArea inside a Div 在Javascript中,是否有一个“如果...发现”的等效项,或者是一种紧凑的方式来执行我想做的事情? - In Javascript, is there an equivalent of a “find if”, or a compact way of doing what I'm trying to do? 如何找出在Chrome控制台中按下按钮后会调用什么功能? - How do I find out what functions are called when a button is pressed in Chrome Console? 我正在尝试在Codepen中构建一个React-Redux&#39;Markdown Previewer&#39;,但是在弄清楚应该做什么方面有很多麻烦 - I'm trying to build a React-Redux 'Markdown Previewer' in codepen, but am having lots of trouble figuring out what is supposed to be doing what 此JavaScript代码有什么问题? 我正在尝试更改的文本 <h1> 点击元素 - What's wrong with this JavaScript code? I'm trying to change the text of <h1> element on click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM