-Поиск по дневнику

Поиск сообщений в rss_thedaily_wtf

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 06.04.2008
Записей:
Комментариев:
Написано: 0


CodeSOD: Wear a Wrap

Среда, 09 Марта 2022 г. 09:30 + в цитатник

While jQuery isn't as popular today as it once was, its still a widely used "utility belt" library. Its popularity arises from the fact that it takes cumbersome APIs and wraps convenience functions around them.

But what if those convenience functions are too convenient, like Ryan's co-worker found. For example, if you want to perform an asynchronous HTTP request using jQuery, you could do something like:

$.ajax({ url: urltosend, type: posttype, data: datatosend, dataType: datatype, context:cntxt, success: successfunction, error: errorfunction });

Now, we can object to passing callbacks directly instead of using promises here, but we have a complex call with a lot of parameters and so we wrap those parameters in an object to ensure they're clearly named and readable. It allows the flexibility of constructing the request in multiple steps before actually sending it.

But what if you don't want any of that, and like counting parameters to make sure you've properly passed your inputs?

function callAjax(urltosend,posttype,datatosend,datatype,cntxt,successfunction,errorfunction){ $.ajax({ url: urltosend, type: posttype, data: datatosend, dataType: datatype, context:cntxt, success: successfunction, error: errorfunction }); }

Now that's convenient.

[Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.

https://thedailywtf.com/articles/wear-a-wrap

Метки:  

 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку