// wrapper for match media
function media (q: string) {
return function (target,method) {
window.addEventListener("resize", () => {
if (window.matchMedia("("+q+")").matches) {
target[method]();
}
});
}
}
//full usage
class Test {
constructor() {
this.doThis();
}
@media("min-width: 400px")
doThis() {
console.log("MQ")
}
}
new Test()
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.