object

JS原型链的理解

自作多情 提交于 2020-01-30 13:43:43
一些个人的理解,不一定是对的,仅供参考。 在JS中有函数和对象两个概念,而又有一切皆对象的概念及函数也是一个对象。所以可以说函数一定可以作为一个对象,而对象不一定是一个函数。 也可以说在js中对象分为两种:1.仅仅是一个对象2.既时对象又是函数(以下称为函数对象) 在JS中有一个概念:所有对象都有__proto__属性,而函数对象则还有prototype属性,可以以此区分出哪些是函数对象 在JS中有两个顶级的内置对象:Object和Function,这两个对象我测试了都属于函数对象。但有所不同的是:Object和Function的__proto__都是ƒ () { [native code] }(native code是已被编译为特定于处理器的 机器码 的代码,我反正就理解为不可见的源代码),Function的prototype为ƒ () { [native code] },Object的prototype是一个对象,里面有一些自己系统自定义的方法 在JS中有一个概念:对象是由函数对象生成的,并且对象的 __proto__ 属性指向函数对象的 prototype 属性;函数(函数对象)也是由函数(函数对象)生成的,并且生成函数(函数对象)的prototype是一个系统默认生成的对象包含了两个属性(constructor和__proto__)

What's the quickest way to rename all property names in a Javascript object?

对着背影说爱祢 提交于 2020-01-30 13:23:13
问题 Say, I have an object that looks like this: const a = { prop1: "val1", prop2: "val2", prop3: "val3", prop4: "val4", } And I want something like this derived from a : const b = { something_prop1: "val1", something_prop2: "val2", something_prop3: "val3", something_prop4: "val4", } Is there any way to achieve this without having to create an intervening array of keys or running a for or foreach loop? 回答1: You could map new objects and build a single object with Object.assign and spread syntax ..

What's the quickest way to rename all property names in a Javascript object?

北城余情 提交于 2020-01-30 13:20:09
问题 Say, I have an object that looks like this: const a = { prop1: "val1", prop2: "val2", prop3: "val3", prop4: "val4", } And I want something like this derived from a : const b = { something_prop1: "val1", something_prop2: "val2", something_prop3: "val3", something_prop4: "val4", } Is there any way to achieve this without having to create an intervening array of keys or running a for or foreach loop? 回答1: You could map new objects and build a single object with Object.assign and spread syntax ..

Object design decision on complicated object C# - HL7 message

非 Y 不嫁゛ 提交于 2020-01-30 12:01:04
问题 I'm attempting to create an object of an HL7 message by parsing a raw text string. The object model is a follows. The object I want to create would be a representation of this, allowing calling methods to access information based on indexes. If information from the 2nd sub-subfield in the 3rd subfield of the 5th field of the segment named "PID" for the message you'd do it like this: HL7Message h = HL7Message(messageRawText); Console.Writeline(h.GetInfo("PID",5,3,2)+" is sub-subfield I'm

Object design decision on complicated object C# - HL7 message

 ̄綄美尐妖づ 提交于 2020-01-30 12:00:25
问题 I'm attempting to create an object of an HL7 message by parsing a raw text string. The object model is a follows. The object I want to create would be a representation of this, allowing calling methods to access information based on indexes. If information from the 2nd sub-subfield in the 3rd subfield of the 5th field of the segment named "PID" for the message you'd do it like this: HL7Message h = HL7Message(messageRawText); Console.Writeline(h.GetInfo("PID",5,3,2)+" is sub-subfield I'm

How to update Array of objects in React js using state

自古美人都是妖i 提交于 2020-01-30 11:41:26
问题 I want to update value of one object only but updating value of one Object, Updates the value for all objects. let default = { name: '', age: '' } this.state = { values: Array(2).fill(default) } updateName (event) { let index = event.target.id, values = this.state.values; values[index].name = event.target.value; this.setState ({ values: values }); } 回答1: There are four significant problems in that code. You're using the same object for all entries in your array. If you want to have different

Declare an object in PHP using constant to hold class name (like you can do with variables)?

℡╲_俬逩灬. 提交于 2020-01-30 10:38:09
问题 This question about syntax/syntax capabilities in PHP. Take for example, using variables to store class names when declaring objects: $className= 'myClass'; $obj = new $className; I was wondering if there were some way to do the same with constants. Something along the lines of: define('CLASS_NAME','myClass'); $obj = new {CLASS_NAME}; This doesn't work. Obviously I could just use a variable as an intermediary step, but I was mostly just wondering for edification purposes whether this was a

What is the standard equivalent of Ruby Hash in C# - How to create a multi dimensional Ruby like hash in C#

此生再无相见时 提交于 2020-01-30 08:38:45
问题 I have prior experience in Ruby and wanted to learn a compiled language and have just picked up C# recently. I am wondering what is the Ruby Equivalent of Hashes in C#. Eg, how can i create a something similar to a Ruby hash below, in C#? x = {"a"=>{"b"=>"c","d"=>["e","f",{"g"=>1}]} What is the standard way to create something like this in C#? Should I use hashtable, dictionary or objects? 回答1: Short answer: There is none. Long answer: The closest C# equivalent is the Dictionary. You can use

Javascript: merge objects by key

試著忘記壹切 提交于 2020-01-30 08:05:28
问题 I have an array of objects that looks like this: var countries = [ {id: SWE, value: 5}, {id: DE, value:10}, {id: SWE, anotherValue: 11}, {id: DE, anotherValue: 15} ] I want to merge array elements by id. The result should look like this: countries = [ {id: SWE, value: 5, anotherValue: 11}, {id: DE, value:10, anotherValue:15} ] Right now, I'm doing this with a for loop and a lot of if and else . Question: is there any (more elegant) javascript inbuilt functionality to achieve this? I've tried

判断对象类型 typeof instanceof Object.prototype.tostring()

半世苍凉 提交于 2020-01-30 06:25:00
常见的有三种方法 1, typeof 2, instance of 3, object.prototype.toString.apply(); 1,typeof typeof 运算符 typeof 是一元运算符,返回结果是一个说明运算数类型的字符串。如:"number","string","boolean","object","function","undefined"(可用于判断变量是否存在)。 但 typeof 的能力有限,其对于Date、RegExp类型返回的都是"object"。如: typeof {}; // "object" typeof []; // "object" typeof new Date(); // "object" 2,instanceof instanceof 运算符。 instanceof 运算符要求其左边的运算数是一个对象,右边的运算数是对象类的名字或构造函数。如果 object 是 class 或构造函数的实例,则 instanceof 运算符返回 true。如果 object 不是指定类或函数的实例,或者 object 为 null,则返回 false。如 [] instanceof Array; // true [] instanceof Object; // true [] instanceof RegExp; // false new