Skip to content
Akin C edited this page Apr 15, 2018 · 13 revisions

Welcome to the Javascript-modifying-arguments-object- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


It is recommended that the Javascript object arguments shouldn`t be modified, because arguments does not completely behave like an array. It is subjucted to automatic coercion rules which could make a function's arguments behaviour hard to predict.

A solution to achieve a safe modification could be by using the slice method. Here follows an example:

function anyFunction()
{
        //"Slice" converts the object "arguments" into an array
	var args = [].slice.call(arguments);
	
	//Outputs all existing arguments
	if(args.length > 0)
        {
		for(var i = 0; i < args.length; i++)
                {
			console.log(args[i]);
		}
	}
}

//Outputs: "Hello", "World" and 42
anyFunction("Hello","World", 42);

Also this kind of modification could give a function the possibility to decide which areas of parameters are allowed to use. Her comes an another example:

function anyFunction(a, b, c, d)
{

	//"Slice" converts the object "arguments" into an array
	var args = [].slice.call(arguments, 2);
	
	//Outputs every argument except the first two
	if(args.length > 0)
	{
		for(var i = 0; i < args.length; i++)
		{
			console.log(args[i]);
		}
	}
}

//Outputs: 42, "is" and "the number"
anyFunction("Hello", "World", 42, "is", "the number");

Content

The user interaction part should look like the content as seen below by starting "index.html" in a web browser.

ERROR: No image found!

  • A: Selecting an ingredient, will mark it by changing its opacity. Also ingredient could be deselected by clicking it.

  • B: After selecting at least one ingredient, clicking on substance should change its form.

  • 🅱️ utton "RESET" will reset all changes.

The colored areas are just for a better readability in the wiki and are not part of the content. To use the project just download the files and execute "index.html". Note that all files(folders "wiki_images" and "PaintNET" excluded) should be placed in the same folder so that the functionality of the code is guaranteed.

The "PaintNet" folder contains a .pdn file which can be opened and altered with PaintNET for simple picture editing.

Clone this wiki locally