Observe that you call obj.draw as :

<button onclick="obj.draw()

The first time obj.draw is called, the context is different than when it called by requestAnimationFramemultiple times, as a callback function before the repaint.

So try by saving this in a variable which is outside the scope of the callback function.

Something like :

var obj = {
    //...

    draw: function () {
        var sender = this;
        var draw = function () {
            document.getElementById(sender.id).style.left = (sender.speed++) + 'px';
            window.requestAnimationFrame(draw);
        }
        draw();
    }
}

Here is an updated demo of how this would look like.

http://stackoverflow.com/questions/6065169/requestanimationframe-with-this-keyword

http://stackoverflow.com/questions/6065169/requestanimationframe-with-this-keyword的更多相关文章

  1. http://stackoverflow.com/questions/12601907/loading-google-maps-in-anonymous-function

    http://stackoverflow.com/questions/12601907/loading-google-maps-in-anonymous-function   window.gMaps ...

  2. https://stackoverflow.com/questions/51751426/failed-to-run-the-da-platform-trial-vm

    https://stackoverflow.com/questions/51751426/failed-to-run-the-da-platform-trial-vm {  "annotat ...

  3. https://stackoverflow.com/questions/40949967/running-storm-from-intellij-nimbus-error

    https://stackoverflow.com/questions/40949967/running-storm-from-intellij-nimbus-error 0down votefavo ...

  4. https://stackoverflow.com/questions/16130292/java-lang-outofmemoryerror-permgen-space-java-reflection

    https://stackoverflow.com/questions/16130292/java-lang-outofmemoryerror-permgen-space-java-reflectio ...

  5. Service vs provider vs factory 转自:http://stackoverflow.com/questions/15666048/service-vs-provider-vs-factory

    请看此链接:http://stackoverflow.com/questions/15666048/service-vs-provider-vs-factory

  6. 国外的非常好的开发提问回答的网站https://stackoverflow.com/questions

    https://stackoverflow.com/questions 可以进行搜索,在页面顶部,有搜索输入框

  7. https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth

    https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth p.p ...

  8. IIS Express 域认证问题(https://stackoverflow.com/questions/4762538/iis-express-windows-authentication)

    option-1: edit \My Documents\IISExpress\config\applicationhost.config file and enable windowsAuthent ...

  9. https://stackoverflow.com/questions/10423781/sql-data-range-min-max-category

    select phone,count(order_id) as c from table_recordgroup by phoneorder by c desc SELECT CASEWHEN (ag ...

随机推荐

  1. 向ES6看齐,用更好的JavaScript(三)

    本文是ES6系列的第三篇,主要介绍ES6新增的数据类型.数据结构,先上传送门: 1 变量部分 2 现有对象拓展 3 新增数据类型/数据结构 4 新的异步编程模式 5 类和模块 1 第七种数据类型Sym ...

  2. Lua自己实现string.split功能

    local function split(str, d) --str是需要查分的对象 d是分界符 local lst = { } local n = string.len(str)--长度 local ...

  3. datatable动态添加,及填充数据

    DataTable tblDatas = new DataTable("Datas"); tblDatas.Columns.Add("ID", Type.Get ...

  4. innerHTML

    对于innerHTML 属性,几乎所有的元素都有innerHTML属性,它是一个字符串,用来设置或获取位于对象起始和结束标签内的HTML.(获取HTML当前标签的起始和结束里面的内容) 下面的例子返回 ...

  5. HDU 2571 命运

    命运 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

  6. 【转】有监督训练 & 无监督训练

    原文链接:http://m.blog.csdn.net/article/details?id=49591213 1. 前言 在学习深度学习的过程中,主要参考了四份资料: 台湾大学的机器学习技法公开课: ...

  7. Android 去除最上面应用名称及图标

    @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); r ...

  8. Why does pthread_cond_signal not work?【转】

    转自:http://stackoverflow.com/questions/16819169/why-does-pthread-cond-signal-not-work# 0 down vote fa ...

  9. WPF:常见问题

    1.自定义Main函数 背景: wpf 默认的Main函数在 App.g.cs文件中,在App.xmal.cs内自定义Main函数后冲突. 解决方法: 法一: 1)新建class1.cs类,在其中设置 ...

  10. postgresql如何实现回收站机制

         在oracle10G之后:oracle提供一种回收站的机制:即闪回技术.闪回技术通常用于快速简单恢复数据库中出现的认为误操作等逻辑错误.发展到11G之后:回收站更加完善:对在可闪回时间内:数 ...