handmade js equivalent