Skip to content
Advertisement

TypeScript static classes

I wanted to move to TypeScript from traditional JS because I like the C#-like syntax. My problem is that I can’t find out how to declare static classes in TypeScript. In C#, I often use static classes to organize variables and methods, putting them together in a named class, without needing to instatiate an object. In vanilla JS, I used

javascript mouse events

Is there a way in javascript to make it so that an “onclick” works for all members of a particular class? So if I have objects A and B that are both of type X, clicking on either of them will call the same function? But that function should only work on whichever of A or B was called, not

Set attribute without value

How do I set a data attribute without adding a value in jQuery? I want this: I tried: Everything else seems to add the second arguments as a string. Is it possible to just set an attribute without value? Answer The attr() function is also a setter function. You can just pass it an empty string. An empty string will

Dynamic textbox creation with db using ajax/javascript/php

I have two tables. company_details and company_specials. Each company_details can have multiple specials. I display the company details at http://eurothermwindows.com/ed/admin.php The first row and fourth row that has the 0 in the active column is from company_details and the rows below are from company_specials. Currently the code allows for dynamic modification of the company_details rows as denoted by the compid

How long is data in localStorage kept?

In JavaScript you have the object localStorage. How long this object will be active for? How long is the the data in it kept for? Answer The most correct answer to this question is: You don’t know. The user could wipe his/her local data at any time, and any type of local storage is subject to user preferences and to

Set window.location with TypeScript

I am getting an error with the following TypeScript code: I am getting an underlined red error for the following: The message says: Does anyone know what this means? Answer window.location is of type Location while .attr(‘data-href’) returns a string, so you have to assign it to window.location.href which is of string type too. For that replace your following line:

localStorage – use getItem/setItem functions or access object directly?

Are there some benefits of using the methods defined on the localStorage object versus accessing the object properties directly? For example, instead of: I have been doing this: Is there anything wrong with this? Answer Not really, they are, basically, exactly the same. One uses encapsulation (getter/setter) to better protect the data and for simple usage. You’re supposed to use

Advertisement