IVYGOU / JavaScript

Learning Notes for JavaScript
0 stars 0 forks source link

Javascript的this用法? #22

Open IVYGOU opened 8 years ago

IVYGOU commented 8 years ago
var x = 1;
  function test(){
    alert(this.x);
  }
  var o={};
  o.x = 1;
  o.m = test;
  o.m.apply( ); //1
IVYGOU commented 8 years ago

JSFIDDLE中执行为undefined,因为函数可能是包含在一个立即函数中执行。