๐ŸŽ TENYO 2026
๐Ÿšš Shipping from 12 USD
๐Ÿ’ฐ DEALS OF THE DAY

Objects

Introduction

Objects are a fundamental feature of the language that allows programmers to represent complex data and organize it into logical structures. Objects in MagiScript are similar to objects in other programming languages like JavaScript, and they are essential for building more advanced programs.

What are Objects?

Objects are collections of key-value pairs that represent a set of related properties and methods. Each key in an object is a string that represents a property, and the value associated with each key can be any valid MagiScript expression. For example, an object representing a person might have properties like “name,” “age,” and “gender,” each with a corresponding value.

Objects can also have methods, which are functions that are associated with the object and can be called using the object’s name. Methods can be used to perform operations on the object’s data or manipulate the object in other ways.

Creating Objects

To create an object, you can use curly braces to define the object’s properties and values.ย For example:

				
					let person = { 
  name: "John",
  age: 25,
  gender: "male",
  sayHello: function() {
    console.log("Hello, my name is " + this.name + ".");
    } 
  }; 
  person.sayHello(); // prints the hello message
				
			

In this example, we’ve created an object called person with properties name, age, and gender. We’ve also defined a method called sayHello that prints a greeting to the console.

Accessing Object Properties

To access the properties of an object, you can use dot notation or square bracket notation.ย For example:

				
					console.log(person.name); // Output: John console.log(person['age']); // Output: 25
				
			

In both cases, we’re accessing the value associated with the name and age properties of the person object.

Using Reflect.ownKeys

MagiScript supports Reflect.ownKeys, which is a method that returns an array of all the keys (both properties and methods) defined on an object.ย For example:

				
					let keys = Reflect.ownKeys(person); 
for (let i = 0; i < keys.length; i++) {
  console.log(keys[i]); // Outputs 'name', 'age', 'gender', and 'sayHello' 
}
				
			

In this example, we’re using Reflect.ownKeys to get an array of all the keys defined on the person object, including both properties and the sayHello method.

Conclusion

Objects are a powerful feature of MagiScript that allow you to represent complex data and organize it into logical structures. By understanding how to create and access object properties, and how to use Reflect.ownKeys to get a list of an object’s keys, you can start building more advanced programs in MagiScript.

Devices & MagiScript

โš›๏ธ Atom Remote

๐Ÿ”ข Quantum Calculator

๐Ÿคนโ€โ™‚๏ธ MagiScript Language

๐Ÿคนโ€โ™‚๏ธ MagiScript Examples

๐Ÿคนโ€โ™‚๏ธ MagiScript Tutorials

General

๐Ÿ“ƒ First Steps

MagiScript Editor

๐Ÿ“ƒ Basics

๐Ÿ“ƒ Keyboard Shortcuts

๐Ÿ“ƒ Running Your First Program

๐Ÿ“ƒ App Store

๐Ÿ“ƒ Atom Settings (Editor)

๐Ÿ“ƒ Debugging Techniques

Input/Output

๐Ÿ“ƒ Buttons

๐Ÿ“ƒ Vibration Motor

๐Ÿ“ƒ RGB LED

๐Ÿ“ƒ Devices

๐Ÿ“ƒ PeekSmith

๐Ÿ“ƒ Quantum

๐Ÿ“ƒ Teleport

๐Ÿ“ƒ Spotted Dice

๐Ÿ“ƒ SB Watch

๐Ÿ“ƒ IARVEL Watch

๐Ÿ“ƒ Fossil Watch

๐Ÿ“ƒ Cosmos Printer

๐Ÿ“ƒ PeriPage Printer

๐Ÿ“ƒ ATC Remote

๐Ÿ“ƒ Labco Scrabble

๐Ÿ“ƒ Bluetooth Keyboard

๐Ÿ“ƒ Bluetooth Mouse

๐Ÿ“ƒ Timers

๐Ÿ“ƒ Database

๐Ÿ“ƒ Events

๐Ÿ“ƒ System (exit, sleep, rand)

๐Ÿ“ƒ Objects (card, time)

Language

๐Ÿ“ƒ Summary

๐Ÿ“ƒ Comments

๐Ÿ“ƒ Variable Declarations

๐Ÿ“ƒ Operators

๐Ÿ“ƒ Control Flow

๐Ÿ“ƒ Functions

๐Ÿ“ƒ Numbers

๐Ÿ“ƒ Strings

๐Ÿ“ƒ Arrays

๐Ÿ“ƒ Objects

๐Ÿ“ƒ Uint8Array