사용자가 자신의 사이트에 삽입 할 수있는 자바 스크립트 파일이 있습니다. coffeescript와 Rails 자산 파이프 라인을 사용하여 여러 개의 파일을 하나의 파일로 컴파일합니다.임베디드 위젯 용 자바 스크립트 캡쳐
# The following dependencies will be compiled into test.js (rails asset pipeline manifest file)
#
#= require jquery
#= require jquery.cookie
jQuery ->
$.cookie('foo', 'bar')
console.log $.cookie('foo')
샘플 페이지 예상대로이 작동 :
<!DOCTYPE html>
<head></head>
<body>
<script src="http://localhost:3000/assets/test.js" type="text/javascript"></script>
</body>
</html>
그러나 어떤 사이트에 임베드해야하므로이 스크립트는 위젯입니다. 사용자가 그 아래에 자신의 jQuery를 추가하는 경우, 다음 일이 휴식 :
이<!DOCTYPE html>
<head></head>
<body>
<script src="http://localhost:3000/assets/test.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</body>
</html>
이 오류 Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'cookie'
그래서 자기가 포함되어 test.js 모든 것을 마무리하는 가장 좋은 방법은 무엇을 주는가? 익명의 함수로 모든 것을 래핑하는 coffeescript가 여기에서 도움이 될 수 있다고 생각했지만 그렇지 않은 것 같습니다.
감사합니다.