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

  • SEARCH
  • Home
  • 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 8582767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:22:30+00:00 2026-06-11T21:22:30+00:00

Hi all I have been learning coffeescript from the book Mark Bates programming in

  • 0

Hi all I have been learning coffeescript from the book Mark Bates programming in coffeescript pdf I have been banging my head off at the behavior of javascript even though both seems to have same implementation

Example-1

class Employee
  constructor: (@attributes)->
    for key, value of @attributes
      @[key] = value
  printInfo: ->
    alert "Name: #{@name}"
emp1 = new Employee
  name: "Mark"
  printInfo: ->
    alert "Hacked ur code !"

emp1.printInfo()

Corresponding javascript

var Emp, Employee, emp1, emp2;

Employee = (function() {

  function Employee(attributes) {
    var key, value, _ref;
    this.attributes = attributes;
    _ref = this.attributes;
    for (key in _ref) {
      value = _ref[key];
      this[key] = value;
    }
  }

  Employee.prototype.printInfo = function() {
    return alert("Name: " + this.name);
  };

  return Employee;

})();

emp1 = new Employee({
  name: "Mark",
  printInfo: function() {
    return alert("Hacked ur code !");
  }
});

emp1.printInfo();
 This alerts "Hacked ur code !"

Example-2

class Emp
  constructor: (@attributes)->
  printInfo: ->
    alert "Name: #{@attributes.name}"
emp2 = new Emp
  name: "Mark"
  printInfo: ->
    alert "Hacked ur code"
emp2.printInfo()

Corresponding javascript

Emp = (function() {

  function Emp(attributes) {
    this.attributes = attributes;
  }

  Emp.prototype.printInfo = function() {
    return alert("Name: " + this.attributes.name);
  };

  return Emp;

})();

emp2 = new Emp({
  name: "Mark",
  printInfo: function() {
    return alert("Hacked ur code");
  }
});

emp2.printInfo();
 This alerts "Name: Mark"

Where is the difference ?

  • 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-06-11T21:22:31+00:00Added an answer on June 11, 2026 at 9:22 pm

    In the first example, all properties of the object you pass to the constructor (attributes) are added to the current instance (that’s what the loop does). Instance properties hide prototype properties, that’s why the printInfo function you passed to the constructor is executed. You can access the original method by using Employee.prototype.printInfo.call(emp1);

    In the second example, nothing like this happens. The attributes object just lives inside the attributes property of the instance. To get a different alert, you need to write emp2.attributes.printInfo();

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

Sidebar

Related Questions

I've recently been learning jQuery Mobile but have a hard time remembering all the
I've been programming with Qt libraries for 3 years. All programs have been designed
I'm a physicist, and have been learning some programming, and have come across a
I have been watching Xcode tutorials on youtube and learning from examples online but
I have been learning ASP.NET MVC recently and everything is going well apart from
WARNING: I have been learning Python for all of 10 minutes so apologies for
I have been slowly learning SQL the last few weeks. I've picked up all
Good day all, I have been learning about databases and database design and I
I have been learning the Factor and J languages to experiment with point-free programming.
I have been learning syntax for PHP and practicing it. I come from a

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.