Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 269291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:48:52+00:00 2026-05-11T23:48:52+00:00

i have some questions about constructors in ColdFusion : must i use the name

  • 0

i have some questions about constructors in ColdFusion :

  1. must i use the name init as the constructor name?
  2. if i create an instance of the component without invoking the init method, what is returned?

    instance=createObject(“component”,”cfcName”); // what value now instance hold

  3. can i take the code in the init method out and delete the init method, then paste the code to the head of the component, is it have a same effect as the init constructor?

great thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:48:53+00:00Added an answer on May 11, 2026 at 11:48 pm

    must i use the name init as the constructor name?

    No, you can name the initialization function any way you like. init() is merely a convention. And it is no real constructor, since it is not automatically called.

    if i create an instance of the component without invoking the init method, what is returned?

    The component instance is returned, as you’d expect it. The presence or absence of an init() function is completely irrelevant. There is no notion of static functions in ColdFusion components, you always get a fully constructed instance from GetObject("component", ...). (Not so for Java objects, which are constructed just before first use, if you forgot to/did not do it manually.)

    can i take the code in the init method out and delete the init method, then paste the code to the head of the component, is it have a same effect as the init constructor?

    Yes, as long as the init() method did not take any parameters, there is no difference.

    However, it is a convention to have a method called init() that returns the component instance. Even if it does nothing apart from “<cfreturn this>“. I’d stay consistent and add one to every component, even if it was not strictly necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some questions about partitioning and strategy, how and when to use it.
I have some questions about basic CSS that I was unable to understand or
I have some questions about customers about NF mode for DB2. Google had very
I have some questions about multi-threaded programming and multi-core usage. In particular I'm wondering
I have some questions about logging, more specifically about setting it up and making
I have some questions about Perl's map function. Specifically: How does %hash = map
There have been some questions about whether or not JavaScript is an object-oriented language.
I´m using a class that encapsulates a thread_group, and have some questions about it
I have some questions about the :visited pseudo-class: Based on what do browsers decide
This is a question I have wondered about for quite some time, yet I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.