kitaro-tn
12/19/2016 - 3:57 PM

JS Bin // source https://jsbin.com/qesodaf

JS Bin

// source https://jsbin.com/qesodaf

var User = (function() {

  var _age;
  
  function User(name) {
    this.name = name;
    _age = 10;
  }

  User.prototype.agree = function() {
    return "Hello, " + this.name;
  };

  User.prototype.age = function() {
    _say.call(this);
    return _age;
  };

  _say = function() {
    console.log(this);
    var _self = this;
    var kuro = function() {
      console.log(User.prototype.agree());
      console.log(_self.agree());
    };
    kuro();
    return "say";
  }

  return User;

})();


var user = new User("Bob");
user.hoge = function() {
  _say.call(this);
};

console.log(user.agree());
console.log(user.name);
console.log(user.age());

console.log(user.hoge());
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>

<script id="jsbin-javascript">
var User = (function() {

  var _age;
  
  function User(name) {
    this.name = name;
    _age = 10;
  }

  User.prototype.agree = function() {
    return "Hello, " + this.name;
  };

  User.prototype.age = function() {
    _say.call(this);
    return _age;
  };

  _say = function() {
    console.log(this);
    var _self = this;
    var kuro = function() {
      console.log(User.prototype.agree());
      console.log(_self.agree());
    };
    kuro();
    return "say";
  }

  return User;

})();


var user = new User("Bob");
user.hoge = function() {
  _say.call(this);
};

console.log(user.agree());
console.log(user.name);
console.log(user.age());

console.log(user.hoge());
</script>



<script id="jsbin-source-javascript" type="text/javascript">var User = (function() {

  var _age;
  
  function User(name) {
    this.name = name;
    _age = 10;
  }

  User.prototype.agree = function() {
    return "Hello, " + this.name;
  };

  User.prototype.age = function() {
    _say.call(this);
    return _age;
  };

  _say = function() {
    console.log(this);
    var _self = this;
    var kuro = function() {
      console.log(User.prototype.agree());
      console.log(_self.agree());
    };
    kuro();
    return "say";
  }

  return User;

})();


var user = new User("Bob");
user.hoge = function() {
  _say.call(this);
};

console.log(user.agree());
console.log(user.name);
console.log(user.age());

console.log(user.hoge());
</script></body>
</html>