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 6354095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:31:21+00:00 2026-05-24T22:31:21+00:00

The difference between getFullName1 and getFullName2 exists ? ViewModel: var viewModel = { firstName:

  • 0

The difference between getFullName1 and getFullName2 exists ?

ViewModel:

var viewModel = {
    firstName: ko.observable("Vasya"),
    lastName: ko.observable("Petrov"),
    getFullName1: function() {
        return this.firstName() + " " + this.lastName();
    }
};

viewModel.getFullName2 = ko.dependentObservable(function() {
    return this.firstName() + " " + this.lastName();
}, viewModel);

// Activates knockout.js
ko.applyBindings(viewModel);

Template

<p>Full name 1: <span data-bind="text: getFullName1()">todo</span></p>
<p>Full name 2: <span data-bind="text: getFullName2()">todo</span></p>
<p>First name: <input data-bind="value: firstName"></p>
  • 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-24T22:31:22+00:00Added an answer on May 24, 2026 at 10:31 pm

    A few things:

    • getFullName1 is not bound to your viewModel, so depending on where it is called, the value of this may not be your viewModel. This is particularly important in Knockout, where your code is being called indirectly and references to functions are passed around. This may not affect you, but especially comes into play when dealing with collections/templates.

    • bindings are implemented using dependentObservables, so in the way that you are using it, they will both update their spans when firstName or lastName changes..

    • Since, getFullName2 is a dependentObservable it will update itself anytime one of its dependencies changes. It does not matter if it is bound to anything. It also has other features available to you like creating manual subscriptions against it.

    • You can also just say test: getFullName2 with a dependentObservable, as it will get unwrapped.

    • The most important reason though is that dependentObservables are only updated when their dependencies change and their actual value is cached inside of it. So, if I called getFullName1 100 times, it would do the work all 100 times. If I called, getFullName2 100 times, it would simply return the latest value that it calculated on creation or when a dependency last changed.

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

Sidebar

Related Questions

//Difference between 2 dates This function works well but display wrong time format. Pls
Is there any difference between int on_exit(void (*function)(int , void *), void *arg); and
The difference between to datetimes is the number of seconds between them. This seems
I want to know difference between recursive function and using a stack in terms
Difference between value parameter and reference parameter ? This question is asked sometime by
Any difference between these two statements? $(document).ready(function() { // Code }); $(function() { //
What´s the difference between: $sql = select * from {$table}; and this: $sql =
What is the difference between function mythemes_preprocess_node(&$variables) { ... } and function mythemes_preprocess_node(&$vars) {
What is the difference between these two? collapse: function(fold) { ... ... } and
Difference between a bus error and a segmentation fault? Can it happen that 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.