<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Объединить объекты]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=17235</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=17235&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Объединить объекты».]]></description>
		<lastBuildDate>Thu, 07 Jul 2022 22:46:07 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Объединить объекты]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153822#p153822</link>
			<description><![CDATA[<p>Хм.. Возможно я перепутал, сейчас смотрел код класса для работы с массивами и нашел там метод &quot;shift&quot; который реализовали как:<br /></p><div class="codebox"><pre><code>shift(arr)
{
	return arr.RemoveAt(1)
}</code></pre></div><p>Значит и мой код можно сократить до:<br /></p><div class="codebox"><pre><code>source := sources.removeAt(1)</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Phoenixxx_Czar)]]></author>
			<pubDate>Thu, 07 Jul 2022 22:46:07 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153822#p153822</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Объединить объекты]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153821#p153821</link>
			<description><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>этот (shift) метод есть у массивов в AHK</p></blockquote></div><p>Где вы его обнаружили? Я о таком ничего не знаю.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Thu, 07 Jul 2022 22:41:23 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153821#p153821</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Объединить объекты]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153820#p153820</link>
			<description><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>source := sources[1]<br />sources.removeAt(1)</p></blockquote></div><p>Вместо этого кода в решении на JS используется &quot;.shift()&quot;, насколько я помню он работает так же, как я написал это другим кодом и насколько я знаю, этот (shift) метод есть у массивов в AHK. Но он почему-то не срабатывает в AHK.<br />Вопрос уже решен добавлением метода &quot;assignDeep&quot;.</p>]]></description>
			<author><![CDATA[null@example.com (Phoenixxx_Czar)]]></author>
			<pubDate>Thu, 07 Jul 2022 22:35:46 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153820#p153820</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Объединить объекты]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153819#p153819</link>
			<description><![CDATA[<p>Я сейчас даже не понял, в чём вопрос. О каком shift() идёт речь, и где он не срабатывает?</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Thu, 07 Jul 2022 22:23:09 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153819#p153819</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Объединить объекты]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153818#p153818</link>
			<description><![CDATA[<p>Пришлось переписать JS код взятый из <a href="https://stackoverflow.com/a/34749873/15606261">поста</a>.</p><div class="codebox"><pre><code>class Object
{
	assign(target, sources*)
	{
		target := Object.clone(target)

		for i, arr in sources
		{
			for key, value in arr
			{
				target[key] := (IsObject(value) &amp;&amp; !value.base.IsArray) ? Object.clone(value, target[key]) : value
			}
		}

		return target
	}

	assignDeep(target, sources*)
	{
		if (!sources.count())
		{
			return target
		}

		source := sources[1]
		sources.removeAt(1)

		if (isObject(target) &amp;&amp; isObject(source))
		{
			for key in source
			{
				if (isObject(source[key]))
				{
					if (!target[key])
					{
						target[key] := {}
					}

					Object.assignDeep(target[key], source[key])
				}
				else
				{
					target[key] := source[key]
				}
			}
		}

		return Object.assignDeep(target, sources*)
	}

	clone(obj)
	{
		cloned := obj.clone()

		for i, key in obj
		{
			if IsObject(key)
			{
				cloned[i] := Object.clone(key)
			}
		}

		return cloned
	}
}
</code></pre></div><p>Мне пришлось использовать такую конструкцию:<br /></p><div class="codebox"><pre><code>source := sources[1]
sources.removeAt(1)</code></pre></div><p>... дабы получить и удалить первый элемент массива, почему не срабатывает <em>.shift()</em>? Метод уходит в бесконечную рекурсию ибо <em>.shift()</em> ничего не возвращает.</p>]]></description>
			<author><![CDATA[null@example.com (Phoenixxx_Czar)]]></author>
			<pubDate>Thu, 07 Jul 2022 21:05:54 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153818#p153818</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Объединить объекты]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153817#p153817</link>
			<description><![CDATA[<p>Я пытался реализовать <em>Object.assing</em> из JS, раньше не особо заморачивался, но сейчас хочу решить одну проблему, я не получаю нужный результат:<br /></p><div class="codebox"><pre><code>class Object
{
	assign(target, sources*)
	{
		target := Object.clone(target)

		for i, arr in sources
		{
			for key, value in arr
			{
				target[key] := (IsObject(value) &amp;&amp; !value.base.IsArray) ? Object.clone(value, target[key]) : value
			}
		}

		return target
	}

	clone(obj)
	{
		cloned := obj.clone()

		for i, key in obj
		{
			if IsObject(key)
			{
				cloned[i] := Object.clone(key)
			}
		}

		return cloned
	}
}
</code></pre></div><div class="codebox"><pre><code>
obj1 := {a: {a: 1}}
obj2 := {a: {b: 2}}
obj3 := {b: 1}

test := Object.assign(obj1, obj2, obj3) ; {&quot;a&quot;: {&quot;b&quot;: 2}, &quot;b&quot;: 1}
; Ожидаемым результатом было: {&quot;a&quot;: {&quot;a&quot;: 1, &quot;b&quot;: 2}, &quot;b&quot;: 1}
</code></pre></div><p>Хотя.. Данный код обрабатывается точно так же и в JS, получается мне нужно что-то типо deepAssign.</p>]]></description>
			<author><![CDATA[null@example.com (Phoenixxx_Czar)]]></author>
			<pubDate>Thu, 07 Jul 2022 20:32:01 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153817#p153817</guid>
		</item>
	</channel>
</rss>
