<script> var DED = function() { var pvar=3; function private_method() { // do stuff here pvar = 5; } return { method_1 : function() { // do stuff here private_method(); alert(pvar); pvar = 6; }, method_2 : function() { // do stuff here alert(pvar); } }; }(); DED.method_1(); DED.method_2(); </script>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
精简后的代码就是
说明它返回的是对象,并不是函数 所以楼上的应该漏看了那个括号
复制对象的话 可以采用以下的代码
当然也可以采用拷贝属性的方式
本身就是一个单体,如何克隆?pvar永远指向DED的内部