Tuesday, November 24, 2015

Prototype javascript 原型的方法

isPrototypeOf(new instance); //判断原型的方法
Object.getPrototypeOf(); //根据实例对象获得原型对象
hasOwnProperty(object, 属性);
in // 操作符 判断属性是否在于实例对象和原型对象中
Object.Keys(); //拿到当前对象里的所有keys 返回一个数组
constructor属性: 该属性是不能被枚举(eable = false)
Object.getOwnPropertyNames 枚举对象所有的属性,不管该内部属性能否被枚举


Sunday, November 22, 2015

javascript ()

if wanna run a function immediately we can use () to run it. the () is run in Javascript.

function test(){
  (function (){
    //run me first,
  })();
// this one used 2 () to run the function first.

   for()....
}

Saturday, November 21, 2015

js this

this  总是指向调用者,也就是说,谁调用了我,我就指向谁。

symfony1 ajax respones and add component on action

json response:
$this->getResponse()->setHttpHeader('Content-type', 'application/json');
return $this->renderText(json_encode($todo));

function addNewTodo(checklist_id)
{
  var body = jQuery('#todo_body_' + checklist_id).val();
    jQuery.ajax({
      url: "url_for('checklist/addtodo'); ?>",
      type: 'POST',
      data: {'id': checklist_id, 'body': body},
      dataType: 'json',
      beforeSend: function () {
        jQuery('#indicator').show();
      },
      success: function (data) {
        jQuery('#indicator').hide();
      }
    });
  return false;
}

component in action:
return $this->renderComponent ('checklist', 'checklist_tr', array(    'todo_id'  =>  $todo->getId(),    'todo_status'  =>  false,    'todo_body'  =>  $todo->getBody(),    'project_id' => $project_id));
function addNewTodo(checklist_id)
{
  var body = jQuery('#todo_body_' + checklist_id).val();
    jQuery.ajax({
      url: "url_for('checklist/addtodo'); ?>",
      type: 'POST',
      data: {'id': checklist_id, 'body': body},
      dataType: 'text',
      beforeSend: function () {
        jQuery('#indicator').show();
      },
      success: function (data) {
        jQuery('#indicator').hide();
      }
    });
  return false;
}