javascript - How to ignore requestAnimationFrame in browsers which don't support it -
Assume that we have a feature / module, which increases a website so it is not really necessary and it I use the Then I can create a new example and "interact with" The problem with this code is that there is an error in IE9 because IE9 does not know the new "function" like "code" requestAnimationFrame . I can simply add a And I use it everywhere. However in the module it would be easier to check the but it prevents old browsers from executing all methods such as ".init ()" or ".method ()" (in this case) Do I really want to give it a I'm not sure that when you already understood the argument, Choose to apply in the form. Just change the comments with the code and you can go: Or check If we can use the You can now requestAnimationFrame , which is like IE8 / 9, I could have polyphil
requestAnimationFrame , but because it is only an increase, the old browser should ignore it. The code of this module looks more or less like this:
; {Function (window, document, undefined) {'strict use'; // example module // constructor function module, option) {// ...} Module.prototype = {init: function () {// if requestAnimationFrame Not supported, a warning warning ("init") should be popped up;}, method: function () {/ if the request animationfreck is not supported, then alert any warning ("Start");}}; Window.Module = Module;} (window, document) should pop up;
var example = new module (document.getElementById ('test'));
instance.init (); Instance.method ();
if statement
(if.re window.requestAnimationFrame) {var instance = new module (document.getElementById ('test')) ; }
requestAnimationFrame support at one time. If this is not supported then nothing should be done, the old browser should ignore it. So I tried to do something
// @constructor function module (L, option) {if (! Window.requestAnimationFrame) {return false; } // ...}
if statement in every code or can I do anything?
Module.prototype = {init: function () {if (requestof requestAnimationFrame === 'undefined') return; Warning ("init"); }};
window.requestAnimationFrame if you wish.
Additional Answer:
How to avoid writing multiple codes,
ifs
statement, as always in javascript, we use the function to implement new 'syntax':
function restricted ) {Return function () {if (requestof requestAnimationFrame === 'undefined') return; Return f.apply (this, logic); }}
restrict (
:
Module.prototype = {init: restricted (function () {alert ("init");}), method: restricted (function () {warning ("start");})}; < / Pre>
Comments
Post a Comment