js中闭包作用举例

it2022-05-05  91

模拟实现类的私有属性

function Boy(name){

  this.name = name;

  var sex = 'boy';

  this.saySex = function(){

    console.log("my sex is "+sex)  };

}

var xiaoming = new Boy('xiaoming');

console.log(xiaoming.name);

console.log(xiaoming.sex);

xiaoming.saySex();VM344:16 xiaomingVM344:18 undefinedVM344:9 my sex is boy

转载于:https://www.cnblogs.com/taojunlong/p/6833338.html

相关资源:各显卡算力对照表!

最新回复(0)