Giter Club home page Giter Club logo

bind-practice's Introduction

Practice: Bind

In this practice, you will practice identifying when to use bind and how to use it.

Set up

Clone the starter from the Download link at the bottom of this page.

Instructions

Implement the following in the employee.js file.

  1. Create a class called Employee.

  2. The constructor method should take in a name and occupation for the Employee and initialize them as instance variables.

  3. Add an instance method called sayName() that will console.log the Employee's name like so: ${name} says hello.

  4. Add another instance method called sayOccupation() that will console.log the Employee's name and occupation like so: ${name} is a ${occupation}.

  5. Export the Employee class from the file.

To test your code, implement the following in the test.js file.

  1. Import the Employee class.

  2. Create a new Employee with the name of "John Wick" and an occupation of "Dog Lover".

  3. Call the sayName() instance method on the new Employee in a setTimeout after 2 seconds. Question: What do you expect to be printed to the terminal and why?

    Answer: "undefined says hello" will be printed to the terminal because the `sayName()` instance method on the new `Employee` was invoked function-style by the `setTimeout` after 2 seconds.
    Solve the problem using `bind` to make sure that "John Wick says hello" will be printed to the terminal after 2 seconds.
  4. Call the sayOccupation() instance method on the new Employee in a setTimeout after 3 seconds. Question: What do you expect to be printed to the terminal and why?

    Answer: "undefined is a undefined" will be printed to the terminal because the `sayOccupation()` instance method on the new `Employee` was invoked function-style by the `setTimeout` after 3 seconds.
    Solve the problem using `bind` to make sure that "John Wick is a Dog Lover" will be printed to the terminal after 3 seconds.

bind-practice's People

Contributors

500ej avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.