DEV Community

Oreoluwa Soyoye
Oreoluwa Soyoye

Posted on

Explanation on Object and Object method

In JavaScript, an object is a collect of properties, and a property can be a value, like a number or string, or a function. When a property is a function, it's called a method.

Here's an example of an object with a method:

JavaScript

const person = {
name: 'Alice',
sayHello: function() {
console.log('Hello, my name is ' + this.name);
}
};
Enter fullscreen mode Exit fullscreen mode

person.sayHello(); // Output: Hello, my name is Alice
In this example, the person object has a property called sayHello that is a function. This function is called a method. When the method is called, it prints a message to the console.

An objector is a special type of object that can be used to object to something. For example, an objector might be used to object to an invalid argument or to an operation that would result in an error.

Here's an example of an objector:

JavaScript

const objector = {
object: function(message) {
console.error(message);
}
};

objector.object('This is an error.');
Enter fullscreen mode Exit fullscreen mode

In this example, the objector object has a method called object that takes a message as an argument. When the method is called, it prints the message to the console as an error.

Objectors can be used to make your code more robust and easier to debug. They can also be used to create custom error messages.

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more