Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In knockout.js, why "this" is being assigned to "self"? [duplicate]

Tags:

knockout.js

I am working through Knockoutjs tutorial. And one thing seems weird to me. I am currently in part 2:

http://learn.knockoutjs.com/#/?tutorial=collections

And in this part in every "class", "this" is being assigned to "self".. it was not the case in the first one?

Why would someone do this? Is it just whoever wrote that particular code has python addiction, or is there some actual benefits to this?

like image 642
galdikas Avatar asked Apr 11 '13 19:04

galdikas


People also ask

What is KnockoutJS used for?

KnockoutJS is basically a library written in JavaScript, based on MVVM pattern that helps developers build rich and responsive websites.

How do I use KnockoutJS in HTML?

It is very easy to use KnockoutJS. Simply refer the JavaScript file using <script> tag in HTML pages. A page as in the following image will be displayed. Click on download link and you will get the latest knockout.


Video Answer


1 Answers

Since "this" refers to different objects depending on context, one can save a reference to a particular object by assigning it to another variable, for example "self".

like image 158
Whistletoe Avatar answered Sep 22 '22 23:09

Whistletoe